Skip to content

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Homework #47

wants to merge 5 commits into from

Conversation

oltanik
Copy link

@oltanik oltanik commented Nov 29, 2023

No description provided.

# ???
count_student = {}
for student_dict in students:
for key, name in student_dict.items():

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():

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)

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):

Choose a reason for hiding this comment

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

Suggested change
def max_count_name(arg, arg2):
def max_count_name(school_class, number_class):



number_class = 0
for school_class in school_students:

Choose a reason for hiding this comment

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

Suggested change
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]}'

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))

Choose a reason for hiding this comment

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

Suggested change
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():

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):

Choose a reason for hiding this comment

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

Suggested change
def student_counting(val, numb):
def student_counting(students, class_num):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy