Open
Conversation
Dzhoker1
reviewed
Dec 15, 2019
| sum_ += 1 | ||
| break | ||
|
|
||
| print("Количество кратных чисел:", sum_) No newline at end of file |
There was a problem hiding this comment.
Похоже вы ушли с урока 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.
А как же генерация массива, которую использовали на уроке и договорились использовать в рамках практической работы?
|
|
||
| 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.
Срезы. Экономим на 1-й итерации цикла и тратим память на почти полную копию массива :-(
| import random | ||
|
|
||
|
|
||
| def get_MaxMin_Inx(source_array): |
There was a problem hiding this comment.
Что за смесь camelCase и snake_case :-)))
|
|
||
| max_ = None | ||
| array = [45, 44, -47, 9, 47, -9, 44, -2, 41, 9] | ||
| for inx, val in enumerate(array[:-1]): |
| print(array) | ||
| res = get_MaxMin_Inx(array) | ||
| print(res) | ||
| sum_ = 0 |
| 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.
Кстати, если размер массива 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Выполнил