Skip to content

Conversation

@AlexN-github
Copy link
Owner

Выполнил

Copy link

@Dzhoker1 Dzhoker1 left a 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

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]

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):

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):

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]):

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

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

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()

Choose a reason for hiding this comment

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

Бедная память.
Решение принимается.

Sign up for free to 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.

3 participants