how can i count the items in a list?

0 votes
can you give an example using a sample list having numbers from 0-10.
May 2 in Python by Waseem
• 2,590 points
54 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes
suppose you have a list

a = [0,1,2,3,4,5,6,7,8,9,10]

now if you want to count the items in your list. you should have a value at your disposal

suppose you want to check the count the number of times 2 is in your list.

a.count(2)

it will give you the count.

In this case if you want the number of items in your list you can just check the length

len(a)

it will give you the number of items in your list.
answered May 2 by Mohammad
• 1,400 points

Related Questions In Python

0 votes
1 answer

How can I get the count of a list in Python?

len() >>> mylist=[] >>> print len(mylist) 0 READ MORE

answered Dec 12, 2018 in Python by charlie_brown
• 7,710 points
42 views
+2 votes
2 answers

In a list of dictionaries, how can I find the minimum calue in a common dictionary field.

There are several options. Here is a ...READ MORE

answered Apr 10, 2018 in Python by charlie_brown
• 7,710 points
31 views
0 votes
1 answer

How can I convert a list of dictionaries from a CSV into a JSON object in Python?

You could try using the AST module. ...READ MORE

answered Apr 17, 2018 in Python by anonymous
472 views
0 votes
1 answer
0 votes
1 answer

How can I find the square of a number in python?

You can use the exponentiation operator or ...READ MORE

answered May 20 in Python by Mohammad
• 1,400 points
14 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.