Conversation
| # ??? | ||
| count_student = {} | ||
| for student_dict in students: | ||
| for key, name in student_dict.items(): |
There was a problem hiding this comment.
здесь не нужна итерация по словарю, можно же просто
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.
видимо эта ошибка идёт через все задания :)
это кстати именно ошибка, потому что может привести к неожиданному поведению, например если структура 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.
как вариант, ещё можно использовать max(), он тоже умеет с аргументом key
| ] | ||
| # ??? | ||
|
|
||
| def max_count_name(arg, arg2): |
There was a problem hiding this comment.
| 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.
| 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.
Вообще это законно, но я бы предложил возвращать просто 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.
| 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.
ага, здесь тоже просто по ключу берём из словаря то, что надо, цикл не нужен
| } | ||
| # ??? | ||
|
|
||
| def student_counting(val, numb): |
There was a problem hiding this comment.
| def student_counting(val, numb): | |
| def student_counting(students, class_num): |
No description provided.