Skip to content

Alexandra Poturaeva - #34

Open
AlexandraPoturaeva wants to merge 9 commits into
learnpythonru:mainfrom
AlexandraPoturaeva:main
Open

Alexandra Poturaeva#34
AlexandraPoturaeva wants to merge 9 commits into
learnpythonru:mainfrom
AlexandraPoturaeva:main

Conversation

@AlexandraPoturaeva

Copy link
Copy Markdown

No description provided.

@AlexandraPoturaevaAlexandraPoturaeva changed the title Alexandra_Poturaeva_hwAlexandraPoturaeva_hw_13.05.2023May 15, 2023

@krepyshkrepysh 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 Outdated
# ???

for name in names:
if is_male[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.

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

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

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

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

@AlexandraPoturaevaAlexandraPoturaevaMay 23, 2023

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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

Comment threadfor_challenges.py Outdated
# ???

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

Copy link
Copy Markdown

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
Copy Markdown
Author

Choose a reason for hiding this comment

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

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

Comment threadfor_challenges.py Outdated
['Вася', 'Маша', 'Саша', 'Женя'],
]
# ??? No newline at end of file
for n in range(1, len(groups) + 1):

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_dict_challenges.py Outdated

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

Copy link
Copy Markdown

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

Comment threadfor_dict_challenges.py Outdated
names = set([x['first_name'] for x in students])
names_freq_dict = dict()

for name in names:

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_dict_challenges.py Outdated
}
for student in group['students']:
if is_male[student['first_name']]:
gender_composition['м'] += 1

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_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']]:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

just else

Comment threadfor_dict_challenges.py Outdated
if is_male[student['first_name']]:
gender_composition['м'] += 1
if not is_male[student['first_name']]:
gender_composition['ж'] += 1

Copy link
Copy Markdown

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
Copy Markdown

Choose a reason for hiding this comment

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

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

@AlexandraPoturaevaAlexandraPoturaevaMay 23, 2023

Copy link
Copy Markdown
Author

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
Copy Markdown

Choose a reason for hiding this comment

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

Отлично!

Comment threadstring_challenges.py Outdated
word_vowels_cnt = 0
for letter in word.lower():
if letter in rus_vowels:
word_vowels_cnt += 1

Copy link
Copy Markdown

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+=letterinrus_vowels

@krepyshkrepysh 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.

Гуд!
Пара вопросов только.

girls_by_class = dict()
boys_by_class = dict()

for group in school:

Copy link
Copy Markdown

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
Copy Markdown

Choose a reason for hiding this comment

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

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

@AlexandraPoturaevaAlexandraPoturaevaMay 26, 2023

Copy link
Copy Markdown
Author

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

@AlexandraPoturaevaAlexandraPoturaeva changed the title AlexandraPoturaeva_hw_13.05.2023Alexandra PoturaevaMay 29, 2023
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.

2 participants

@AlexandraPoturaeva@krepysh