Conversation
ad3002
left a comment
There was a problem hiding this comment.
Задачки решены правильно! Есть вопросы по стилистике. Часть решений можно сделать сильно быстрей, часть решений можно написать одной строкой.
|
|
||
| ''' def unique_in_order(unique:str): | ||
| list_1 = [] | ||
| for id in range(len(unique)): |
There was a problem hiding this comment.
len(unique) - в переменную нужно вынести, ты каждый раз вычисляешь ее
| pass | ||
| else: | ||
| list_1.append(unique[id]) | ||
| return list_1 ''' |
| # 1. Unique on order | ||
|
|
||
| ''' def unique_in_order(unique:str): | ||
| list_1 = [] |
There was a problem hiding this comment.
странное название переменной, нужно переназвать чтобы было понятно что в ней
| list_1 = [] | ||
| for id in range(len(unique)): | ||
| if id == len(unique) - 1: | ||
| list_1.append(unique[id]) |
There was a problem hiding this comment.
не нужное условие, тут два более питоньих решения 1) сделать через enumerate 2) одной строкой через filter
| # 1. Unique on order | ||
|
|
||
| ''' def unique_in_order(unique:str): | ||
| ``` def unique_in_order(unique:str): |
There was a problem hiding this comment.
три лапки слово питон новая строка
|
|
||
| ```python | ||
| def disemvowel(string_): | ||
| for i in "aeiouAEIOU": |
There was a problem hiding this comment.
Опять сложность квадратичная, можно сделать линейно, подсказка, используй
return "".join(...)
| def get_middle(s): | ||
| if len(s) % 2 == 0: | ||
| return s[(len(s) // 2) - 1 : (len(s) // 2) + 1] | ||
| elif len(s) % 2 != 0: |
There was a problem hiding this comment.
тут должен быть else, ни в одном языке нет конструкции if ... else if ...
There was a problem hiding this comment.
и позицию среднего элемента в отдельную переменную, чтобы не считать ее каждый раз
| list_1 = [] | ||
| for i in a: | ||
| if i in b: | ||
| pass |
There was a problem hiding this comment.
if ... pass else something не надо испльзовать
она равнозначна конструкции одного if, еще это можно одной строкой
| ```python | ||
| def likes(names): | ||
| if len(names) == 0: | ||
| return "no one likes this" |
There was a problem hiding this comment.
Есть три варианта использования кавычек, у тебя перемешано
- двойные кавычки строки, одинарные символы (у нас)
- везде двойные
- везде одинарные
| # [10. Unique on order.] | ||
| ```python | ||
| def to_time(seconds): | ||
| return f"{seconds//3600} hour(s) and {seconds%3600//60} minute(s)" |
There was a problem hiding this comment.
в целом вычисление в темплейтах плохо, это очень сложно и читать и поддерживать
внутри темплейта должны быть переменные
Исправила решения и добавила новые
Add codware