Skip to content

challenges - #18

Open
stephdkv wants to merge 1 commit into
learnpythonru:mainfrom
stephdkv:homework
Open

challenges#18
stephdkv wants to merge 1 commit into
learnpythonru:mainfrom
stephdkv:homework

Conversation

@stephdkv

Copy link
Copy Markdown

No description provided.

@n05tr0m0n05tr0m0 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Прокомментировал

Comment threadfor_challenges.py
if is_male[name]:
print(f'{name} мужской род')
else:
print(f'{name} женский род')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Можно одной строкой в данном случае:

print(name, 'мужской пол') ifis_male[name] elseprint(name, 'женский пол')


students_names = count_name(students)
for name, repeats in students_names.items():
print(f'{name}: {repeats}')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Решение без Counter для ознакомления:

count_students= {}
forstudentinstudents:
ifstudent['first_name'] notincount_students.keys():
count_students[student['first_name']] =1else:
count_students[student['first_name']] +=1print(count_students)
forname, countincount_students.items():
print(f"{name}: {count}")

names = count_name(students)
most_common_name = name_max_value(names)
print(f'Самое частое имя в классе: {most_common_name}')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Решение без Counter, для ознакомления:

students_list= [student['first_name'] forstudentinstudents]
print("Самое частое имя среди учеников:", max(set(students_list), key=students_list.count))

for i, school_class in enumerate(school_students):
names = count_name(school_class)
most_common_name = name_max_value(names)
print(f'Самое частое имя в классе {i+1}: {most_common_name}')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Переиспользование уже написанных функций хороший подход.
Публикую решение без использования Counter для ознакомления:

fornum, studentsinenumerate(school_students, start=1):
students_list= [student['first_name'] forstudentinstudents]
print(f"Самое частое имя в классе {num}: {max(set(students_list), key=students_list.count)}")

Почитай, попробуй разобраться как это работает, если не получится, напиши мне.

for school_class in school:
gender = students_gender(school_class['students'])
class_name = school_class['class']
print(f"Класс {class_name}: девочки {gender['Female']}, мальчики {gender['Male']}")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ещё два способа решения для этой задачи для ознакомления:

forclass_inschool:
count_boys=0count_girls=0forstudentinclass_['students']:
ifis_male[student['first_name']]:
count_boys+=1else:
count_girls+=1print(f"Класс {class_['class']}: девочки {count_girls}, мальчики {count_boys}")
print("альтернативный способ") # альтернативный способforclass_inschool:
female= [name['first_name'] fornameinclass_['students'] ifnotis_male[name['first_name']]]
male= [name['first_name'] fornameinclass_['students'] ifis_male[name['first_name']]]
print(f"Класс {class_['class']}: девочки {len(female)}, мальчики {len(male)}")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Когда разберёшь, выполни 5-е задание

Sign up for freeto 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.

3 participants

@stephdkv@n05tr0m0@freenlol