Linked Questions

762 votes
8 answers
1.7m views

In Python, is the following the only way to get the number of elements? arr.__len__() If so, why the strange syntax?
Joan Venge's user avatar
  • 334k
300 votes
7 answers
1.1m views

I am trying to find a simple way of getting a count of the number of elements in a list: MyList = ["a", "b", "c"] I want to know there are 3 elements in this list.
Bruce's user avatar
  • 3,089
208 votes
5 answers
830k views

How can I count the number of elements in an array, because contrary to logic array.count(string) does not count all the elements in the array, it just searches for the number of occurrences of string....
UnkwnTech's user avatar
  • 91.4k
34 votes
3 answers
97k views

Hey this is a demo to show some of my classmates an intro to python and coding. The code below should be able to take a list like [0,1] and if run using the average function would return 0.5. When run ...
Ragnar's user avatar
  • 1,602
10 votes
1 answer
15k views

I've got an array (list) that I want to check if it's size is equal to 1, if it is then it needs to append a new like as shown. ## If appended data = 1 then append the new line: if appended_data == 1:...
Ryflex's user avatar
  • 5,797
7 votes
2 answers
2k views

Im trying to make a function that takes from 1 up to 5 arguments and does different calculations depending on the number given. My idea was something like this: def function(*args) num_of_args = (...
user avatar
-2 votes
1 answer
14k views

I have a list like this : test=[[1, 0, 0, 0], [1, 0, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0], [1, 0, 0, 0], [1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1], [1, 0,...
Estina Esitna's user avatar
-3 votes
1 answer
2k views

Possible Duplicate: Get the size of a list in python? I need to be able to count how many values there are in total there are in a list. eg. [1,5,9,4,6], there are 5 values. I have tried using the ...
Daniel Nitschke's user avatar
0 votes
4 answers
1k views

How do I count the number of elements in a nested list? I want to transform: myList = [[0],[1,4,5,8],[5],[2,3,9],[7,7]] into: myList = [1, 4, 1, 3, 2]
jjwright's user avatar
0 votes
2 answers
2k views

I am receiving the count of each line in each list, I am looking to sum each particular values of entire list, (Nested lists included) [[3],[4],][1],[3]] = * 11 is my desired result. example: code ...
CabMod's user avatar
  • 21
0 votes
1 answer
664 views

I use the method split() of the string class and supposedly it returns a list, but it isn't a common list because I can't use list methods like count() I've tried to use the count method of list but ...
Oscar Gonzalez's user avatar
-1 votes
1 answer
408 views

For example, list[1, 2, 3] has 3 items (and indexex 0, 1, 2). How can I print the number of objects in a list? In this istance, it would be "3".
Vinícius Sosnowski's user avatar
-1 votes
1 answer
232 views

class Artist(db.Model): id = db.Column(db.Integer(), primary_key=True) artist_name = db.Column(db.String(200)) albums = db.relationship('Album', backref='artist'...
saajid pasha's user avatar
1 vote
0 answers
47 views

I am trying to count the number of features detected by MSER feature detection algorithm in OPenCV Python. I have no idea how to do that. I would greatly appreciate it if someone helped me figure out ...
Ririe Sakamaki's user avatar
-3 votes
2 answers
67 views

Here is an example of a list of lists. [["Amber", "7.3"], ["Molly", "14.5"], ["Lisa"]] As you can see, there are two lists that have a second element....
iylila's user avatar
  • 5

15 30 50 per page