python count number of items in list code example

Example 1: python find the number of elements in a list

list1 = [2,3,4,3,10,3,5,6,3]
elm_count = list1.count(3)
print('The count of element: 3 is ', elm_count)

Example 2: how to count things in a list python

list.count(element)

list1 = ['red', 'green', 'blue', 'orange', 'green', 'gray', 'green']
color_count = list1.count('green')
print('The count of color: green is ', color_count)

Example 3: number of elements in list in python

# List of strings
listOfElems = ['Hello', 'Ok', 'is', 'Ok', 'test', 'this', 'is', 'a', 'test']
len(s)

Example 4: how to find length of list python

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

length_of_list = len(my_list)

Example 5: count number items in list python

mylist = ["abc", "def", "ghi", "jkl", "mno", "pqr"]

print(len(mylist))

# output 6

Example 6: python count value in list

from collections import Counterli = ['blue', 'pink', 'green', 'green', 'yellow', 'pink', 'orange']Counter(li)#=> Counter({'blue': 1, 'pink': 2, 'green': 2, 'yellow': 1, 'orange': 1})