-
Notifications
You must be signed in to change notification settings - Fork 0
Lesson03 #3
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: master
Are you sure you want to change the base?
Lesson03 #3
Conversation
Dzhoker1
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.
Оставил комментарии по коду
| sum_ += 1 | ||
| break | ||
|
|
||
| print("Количество кратных чисел:", sum_) No newline at end of file |
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.
Похоже вы ушли с урока 2 пораньше, не услышали описание алгоритма и решили не ту задачу.
| # надо заполнить значениями 0, 3, 4, 5, (индексация начинается с нуля), | ||
| # т.к. именно в этих позициях первого массива стоят четные числа. | ||
|
|
||
| array1 = [4,6,3,6,8,5,9,34,57,78,44,23,55,62] |
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.
А как же генерация массива, которую использовали на уроке и договорились использовать в рамках практической работы?
|
|
||
| def get_MaxMin_Inx(source_array): | ||
| max_inx = min_inx = 0 | ||
| for inx, val in enumerate(source_array[1:], 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.
Срезы. Экономим на 1-й итерации цикла и тратим память на почти полную копию массива :-(
| import random | ||
|
|
||
|
|
||
| def get_MaxMin_Inx(source_array): |
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.
Что за смесь camelCase и snake_case :-)))
|
|
||
| max_ = None | ||
| array = [45, 44, -47, 9, 47, -9, 44, -2, 41, 9] | ||
| for inx, val in enumerate(array[:-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.
Принимается
| print(array) | ||
| res = get_MaxMin_Inx(array) | ||
| print(res) | ||
| sum_ = 0 |
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.
Отличная доработка
| else: | ||
| range_start = res["max_inx"] + 1 | ||
| range_end = res["min_inx"] | ||
| for i in array[range_start:range_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.
Кстати, если размер массива 1 Гб, а искомые элементы окажутся в начале и конце, получим копию в 1Гб для этого цикла. Впрочем, не стоит переживать. Копию чаще всего будет 333-500 Мб ;-)
|
|
||
| source_array = [4,6,3,6,8,5,9,34,57,78,1,23,8,62] | ||
| print(source_array) | ||
| array = source_array.copy() |
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.
Бедная память.
Решение принимается.
Выполнил