-
Notifications
You must be signed in to change notification settings - Fork 260
Alexandra Poturaeva #34
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?
Conversation
krepysh
left a comment
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_challenges.py
Outdated
| # ??? | ||
|
|
||
| for name in names: | ||
| if is_male[name]: |
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.
Научу плохому. Можно так сделать:
| if is_male[name]: | |
| gender = "жм"[is_male[name]] |
Работает потому что False это 0, и мы берем элемент строки с нулевым индексом.
Можно даже:
| if is_male[name]: | |
| gender = ("woman", "man")[is_male[name]] |
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_challenges.py
Outdated
| # ??? | ||
|
|
||
| print(f'Всего {len(groups)} группы.') | ||
| for n in range(1, len(groups) + 1): |
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.
У enoumerate есть start.
Всегда когда тебе нужен и объект и номер используй enoumerate
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_challenges.py
Outdated
| ['Вася', 'Маша', 'Саша', 'Женя'], | ||
| ] | ||
| # ??? | ||
| for n in range(1, len(groups) + 1): |
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_dict_challenges.py
Outdated
|
|
||
| for name in names: | ||
| name_count = 0 | ||
| for student in 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.
слишком много раз проходишь по names - students.
Можно всего раз пройти по students
Используй словарь из str -> int, каждый элемент это то сколько раз встречалось имя.
for_dict_challenges.py
Outdated
| names = set([x['first_name'] for x in students]) | ||
| names_freq_dict = dict() | ||
|
|
||
| for name in names: |
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_dict_challenges.py
Outdated
| } | ||
| for student in group['students']: | ||
| if is_male[student['first_name']]: | ||
| gender_composition['м'] += 1 |
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_dict_challenges.py
Outdated
| for student in group['students']: | ||
| if is_male[student['first_name']]: | ||
| gender_composition['м'] += 1 | ||
| if not is_male[student['first_name']]: |
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.
just else
for_dict_challenges.py
Outdated
| if is_male[student['first_name']]: | ||
| gender_composition['м'] += 1 | ||
| if not is_male[student['first_name']]: | ||
| gender_composition['ж'] += 1 |
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.
попробуй оставить в блоках if только выбор ключа, а инкремент вынести наружу.
| girls_by_class = dict() | ||
| boys_by_class = dict() | ||
|
|
||
| for group in school: |
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.
Разбить на отдельные функции, переиспользовать код по возможности.
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.
Смогла добавить только одну функцию, а вторую взяла из предыдущих упражнений по именам (find_items_with_max_values). Норм?
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.
Отлично!
string_challenges.py
Outdated
| word_vowels_cnt = 0 | ||
| for letter in word.lower(): | ||
| if letter in rus_vowels: | ||
| word_vowels_cnt += 1 |
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.
Слегка спорное решение, но мне нравится. Можно добавлять bool в инкременте, True=1, False=0
На твое усмотрение
| word_vowels_cnt += 1 | |
| word_vowels_cnt += letter in rus_vowels |
krepysh
left a comment
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.
Гуд!
Пара вопросов только.
| girls_by_class = dict() | ||
| boys_by_class = dict() | ||
|
|
||
| for group in school: |
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.
Отлично!
| case (18, 24): | ||
| return 'вечером (после 18 часов)' | ||
|
|
||
| return f'c {prime_time_info[0][0][0]} до {prime_time_info[0][0][1]} часов' |
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.
А вроде же до этого return мы не доходим?
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.
Конкретно в этой задаче, когда передаём часы 12 и 18, не доходим, поэтому здесь в общем-то бесполезно оно. Но если передать, например, 10, 13, 15, то этот return сработает
No description provided.