how can i count the items in a list

+1 vote
can you give an example using a sample list having numbers from 0-10.
May 2, 2019 in Python by Waseem
• 4,540 points
4,007 views

2 answers to this question.

+1 vote
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, 2019 by Mohammad
• 3,230 points
+2 votes

Syntax :

           list. count(value)

Code:

colors = ['red', 'green', 'blue', 'black']

Return the number of times the value' blue' appears int in the colors list

x= colors.count("blue")
print(x)
Output: 1
answered Jul 7, 2019 by Neha
• 330 points

edited Jul 8, 2019 by Kalgi

Related Questions In Python

0 votes
2 answers

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

n=[1,2,3,4,5,6,7,8,9] print(len(n)) =9 READ MORE

answered Dec 10, 2020 in Python by anonymous
1,165 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,720 points
1,054 views
0 votes
1 answer
0 votes
1 answer

How can I count the occurrences of a list item?

If you only want one item's count, ...READ MORE

answered Dec 18, 2020 in Python by Gitika
• 65,910 points
471 views
0 votes
1 answer

How can I count the occurrences of a list item?

For Counting the occurrences there are many ...READ MORE

answered Feb 7, 2022 in Python by Nandini
• 5,480 points
261 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
3,215 views
0 votes
2 answers
0 votes
1 answer
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP