user18393
0
Q:

count occu elements in list python

#	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
from collections import Counter 
  
# declaring the list 
l = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5] 
  
# driver program 
x = 3
d = Counter(l) 
print('{} has occurred {} times'.format(x, d[x])) 
0
# 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