-
Notifications
You must be signed in to change notification settings - Fork 0
work done #1
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?
work done #1
Conversation
for_challenges.py
Outdated
|
|
||
| print(f'Всего {len(groups)} группы.') | ||
| for i in groups: | ||
| print(f'Группа {groups.index(i) + 1}: {len(i)} ученика') |
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.
index в list работает не супер эффективно (перебор, то есть O(n))
Если нужно одновременно обращаться и к индексу и к элементу есть два подхода:
- Итерируемся по индексу
for i in len(groups): - Используем enumerate что бы получать объект и индекс одноврменно:
for index_number, group in enumerate(groups)
Вариант с enumerate может казаться менее интуитивным, но рекомендую с ним разобраться - это супер распространенная конструкция в питоне. Будет легче понимать чужой код.
for_challenges.py
Outdated
| # ??? | ||
| student=[] | ||
| for i in groups: | ||
| print(f'Группа {groups.index(i) + 1}:',end=' ') |
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.
тоже index
for_challenges.py
Outdated
| ] | ||
| # ??? | ||
| student=[] | ||
| for i in groups: |
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.
Здесь и в других местах лучше использовать более self-explanatory name для iteration variable. group было бы хорошо.
Однобуквенные переменные i,j,k используем для итерирования по индексам только.
for_challenges.py
Outdated
| for i in groups: | ||
| print(f'Группа {groups.index(i) + 1}:',end=' ') | ||
| for j in range(len(i)): | ||
| print(i[j],end='') |
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.
i[j] супер неожиданная (и непонятная) конструкция - пофикситься когда переименуешь.
for_challenges.py
Outdated
| for j in range(len(i)): | ||
| print(i[j],end='') | ||
| if j != len(i) - 1: | ||
| print(',',end='') |
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.
Что бы упростить логику вывода можно использовать строковый метод join что бы сформировать строку и потом ее разом напечатать.
groups_as_str = ', '.join(groups)
for_dict_challenges.py
Outdated
| names = dict() | ||
|
|
||
| for student in students: | ||
| if student['first_name'] not in names.keys(): |
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 student['first_name'] not in names.keys(): | |
| if student['first_name'] not in names: |
так достаточно.
No description provided.