Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions for_dict_challenges.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@
]

print('Задание 1')
qty_students = (Counter(student['first_name'] for student in students))
for student in qty_students:
print(f'{student}: {qty_students[student]}')
# qty_students = (Counter(student['first_name'] for student in students))
# for student in qty_students:
# print(f'{student}: {qty_students[student]}')
# print()
unique_students = []
for student in students:
if student['first_name'] not in unique_students:
unique_students.append(student['first_name'])
for student in unique_students:
print(f"{student}: {students.count({'first_name': student})}")

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#42 (comment)
Попробовал без Counter

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А зачем тебе отдельный unique_students, если ты можешь проверять напрямую в словаре? проверка находится ли ключ в словаре работает ощутимо быстрее, чем проверка есть ли значение в словаре

print()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough.
работать будет. А можешь любое из этих заданий сделать напрямую через словари, без counter?



Expand Down Expand Up @@ -134,9 +141,11 @@
else:
female[grade] += 1

most_male = school[male.index(max(male))]['class']
most_female = school[female.index(max(female))]['class']
most_male_index = male.index(max(male))
most_male_class = school[most_male_index]['class']
most_female_index = female.index(max(female))
most_female_class = school[most_female_index]['class']
print(
f"Больше всего мальчиков в классе {most_male}")
f"Больше всего мальчиков в классе {most_male_class}")
print(
f"Больше всего девочек в классе {most_female}")
f"Больше всего девочек в классе {most_female_class}")

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#42 (comment)
Решил располовинить на индекс класса и класс)