-
Notifications
You must be signed in to change notification settings - Fork 260
Homework #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Homework #47
Conversation
# ??? | ||
count_student = {} | ||
for student_dict in students: | ||
for key, name in student_dict.items(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
здесь не нужна итерация по словарю, можно же просто
name = student_dict['first_name']
остальное ок
|
||
counter_student_name_max = {} | ||
for students_dict in students: | ||
for key, name in students_dict.items(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
видимо эта ошибка идёт через все задания :)
это кстати именно ошибка, потому что может привести к неожиданному поведению, например если структура student_dict расширится вот таким образом
{'first_name': 'Вася', 'mother_name': 'Галя', 'father_name': 'Вася', 'pet_name': 'Вася'}
counter_student_name_max[name] += 1 | ||
else: | ||
counter_student_name_max[name] = 1 | ||
name = sorted(counter_student_name_max.items(), key=lambda item: item[1], reverse=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
как вариант, ещё можно использовать max(), он тоже умеет с аргументом key
@@ -51,7 +67,24 @@ | |||
{'first_name': 'Саша'}, | |||
], | |||
] | |||
# ??? | |||
|
|||
def max_count_name(arg, arg2): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def max_count_name(arg, arg2): | |
def max_count_name(school_class, number_class): |
|
||
|
||
number_class = 0 | ||
for school_class in school_students: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for school_class in school_students: | |
for number_class, school_class in enumerate(school_students): |
counter_student_name_max[name] = 1 | ||
name_student = sorted(counter_student_name_max.items(), key=lambda item: item[1], reverse=True) | ||
|
||
return f'Самое частое имя в классе {arg2}: {name_student[0][0]}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Вообще это законно, но я бы предложил возвращать просто name_student[0][0], а весь пост-процессинг делать за пределами функции. Таким образом мы немножко улучшим чистоту кода.
number_class = 0 | ||
for school_class in school_students: | ||
number_class += 1 | ||
print(max_count_name(school_class, number_class)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
print(max_count_name(school_class, number_class)) | |
most_frequent_name = max_count_name(school_class) | |
print(f'Самое частое имя в классе {number_class}: {most_frequent_name }') |
|
||
|
||
for classes in school: | ||
for key, value in classes.items(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ага, здесь тоже просто по ключу берём из словаря то, что надо, цикл не нужен
@@ -72,7 +105,26 @@ | |||
'Миша': True, | |||
'Даша': False, | |||
} | |||
# ??? | |||
|
|||
def student_counting(val, numb): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def student_counting(val, numb): | |
def student_counting(students, class_num): |
No description provided.