Micah
0
Q:

how to count things in a list python

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

print(len(mylist))

# output 6
2
#	How to use the len function:

list = ["Elefant", "Snake", "Penguin"]

print(len(list))

#	Explanation:
#	>print(len(list))<
#	With the 'len' function Python counts the amount of elements in a list (The length of the list).
#	In this case the output is '3' because there are 3 elements in the list.
3
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)
3
# vowels list
vowels = ['a', 'e', 'i', 'o', 'i', 'u']

# count element 'i'
count = vowels.count('i')

# print count
print('The count of i is:', count)

# count element 'p'
count = vowels.count('p')

# print count
print('The count of p is:', count)
1
randomList = ['Hi', 'text', 420, 'Hello World', 'abcde', 'Sub2Technoblade']
print(len(randomList))
2
#	How to use the .count function:

list = ["Elefant", "Snake", "Penguin", "Penguin"]

print(list.count("Penguin"))

# 	Explanation:
#   >(list name) + .count + (element)<
#   With the '.count' function Python counts how many of the elements you named are in the list.
#   In this case the output is '2' because The element 'Penguin' appears twice in the list.
1

New to Communities?

Join the community