xxxxxxxxxx
student_grades = [9.1, 8.8, 10.0, 7.7, 6.8, 8.0, 10.0, 8.1, 10.0, 9.9]
samebnumber = student_grades.count(10.0)
print(samebnumber)
xxxxxxxxxx
from collections import Counter
1ist1 = ['Peter', 'Rose', 'Donald', 'Peter']
a = Counter(listl).get('Peter')
print(f'Peter appears in the list {a} times')
# Output:
# Peter appears in the list 2 times
xxxxxxxxxx
indices = [index for index, element in enumerate(a_list) if element == 1]
xxxxxxxxxx
#import the Counter class from collections module
from collections import Counter
#An iterable with elements to count
data = 'aabbbccccdeefff'
#create the Counter object
c = Counter(data)
print(c)
#get the count of a specific element
print(c['f'])
xxxxxxxxxx
# Basic syntax:
your_list.count("element")
# Example usage:
your_list = [12, 54, 67, 86, 89, 12, 54, 67, 67, 66]
your_list.count(67)
--> 3
xxxxxxxxxx
#Count the frequency of elements in a list using dictionary
l=eva1.l(input("Enter the list"))
d={}
print(l)
for i in l:
if i not in d:
d[i]=l.count(i)
else:
pass
print("Frequency of element:")
for i in d:
print(i,"-",d[i])
output:
Enter the list[1,5,8,7,5,6,3,2,4,7,5,1,]
[1, 5, 8, 7, 5, 6, 3, 2, 4, 7, 5, 1]
Frequency of element:
1 - 2
5 - 3
8 - 1
7 - 2
6 - 1
3 - 1
2 - 1
4 - 1
xxxxxxxxxx
Map<String, Long> counts =
list.stream().collect(Collectors.groupingBy(e -> e, Collectors.counting()));