students = [
{'first_name': 'Вася'},
{'first_name': 'Петя'},
{'first_name': 'Маша'},
{'first_name': 'Маша'},
{'first_name': 'Петя'},
]
# Пример вывода:
# Вася: 1
# Маша: 2
# Петя: 2
students = [
{'first_name': 'Вася'},
{'first_name': 'Петя'},
{'first_name': 'Маша'},
{'first_name': 'Маша'},
{'first_name': 'Петя'},
]
names = dict()
for student in students:
if student['first_name'] not in names.keys():
names[student['first_name']] = 1
else:
names[student['first_name']] += 1
for name, count in names.items():
print(f'{name}: {count}')
names = [s['first_name'] for s in students]
for name in set(names):
print(f'{name}: {names.count(name)}')
from collections import Counter
from operator import itemgetter
Counter(map(itemgetter('first_name'), students))
Counter(map(lambda student: student['first_name'], students))