Skip to content

Conversation

@AlexandraPoturaeva
Copy link

No description provided.

@AlexandraPoturaeva AlexandraPoturaeva changed the title Alexandra_Poturaeva_hw AlexandraPoturaeva_hw_13.05.2023 May 15, 2023
Copy link

@krepysh krepysh left a comment

Choose a reason for hiding this comment

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

Отлично.
Попробуй больше обращать внимание на декомпозицию "сложных" кусков кода на более простые, и переиспользование кода при помощи функций. Обычно если код повторяется несколько раз он сложнее для понимания и изменения.

# ???

for name in names:
if is_male[name]:
Copy link

Choose a reason for hiding this comment

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

Научу плохому. Можно так сделать:

Suggested change
if is_male[name]:
gender = "жм"[is_male[name]]

Работает потому что False это 0, и мы берем элемент строки с нулевым индексом.
Можно даже:

Suggested change
if is_male[name]:
gender = ("woman", "man")[is_male[name]]

Copy link
Author

@AlexandraPoturaeva AlexandraPoturaeva May 23, 2023

Choose a reason for hiding this comment

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

Офигенно!!) спасибо

# ???

print(f'Всего {len(groups)} группы.')
for n in range(1, len(groups) + 1):
Copy link

Choose a reason for hiding this comment

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

У enoumerate есть start.
Всегда когда тебе нужен и объект и номер используй enoumerate

Copy link
Author

Choose a reason for hiding this comment

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

да, точно, забыла про это, спасибо!

['Вася', 'Маша', 'Саша', 'Женя'],
]
# ???
for n in range(1, len(groups) + 1):
Copy link

Choose a reason for hiding this comment

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

аналогично


for name in names:
name_count = 0
for student in students:
Copy link

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, каждый элемент это то сколько раз встречалось имя.

names = set([x['first_name'] for x in students])
names_freq_dict = dict()

for name in names:
Copy link

Choose a reason for hiding this comment

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

Используй решение предыдущей задачи как функцию

}
for student in group['students']:
if is_male[student['first_name']]:
gender_composition['м'] += 1
Copy link

Choose a reason for hiding this comment

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

Нет ни одной причины использовать кирилические ключи в этом словаре.

for student in group['students']:
if is_male[student['first_name']]:
gender_composition['м'] += 1
if not is_male[student['first_name']]:
Copy link

Choose a reason for hiding this comment

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

just else

if is_male[student['first_name']]:
gender_composition['м'] += 1
if not is_male[student['first_name']]:
gender_composition['ж'] += 1
Copy link

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:
Copy link

Choose a reason for hiding this comment

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

Разбить на отдельные функции, переиспользовать код по возможности.

Copy link
Author

@AlexandraPoturaeva AlexandraPoturaeva May 23, 2023

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). Норм?

Copy link

Choose a reason for hiding this comment

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

Отлично!

word_vowels_cnt = 0
for letter in word.lower():
if letter in rus_vowels:
word_vowels_cnt += 1
Copy link

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
На твое усмотрение

Suggested change
word_vowels_cnt += 1
word_vowels_cnt += letter in rus_vowels

Copy link

@krepysh krepysh left a 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:
Copy link

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]} часов'
Copy link

Choose a reason for hiding this comment

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

А вроде же до этого return мы не доходим?

Copy link
Author

@AlexandraPoturaeva AlexandraPoturaeva May 26, 2023

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 сработает

@AlexandraPoturaeva AlexandraPoturaeva changed the title AlexandraPoturaeva_hw_13.05.2023 Alexandra Poturaeva May 29, 2023
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