Skip to content

Added solution of task 1-9.#3

Merged
masterjr86 merged 1 commit intoLesson_2from
Lesson_3
Mar 10, 2020
Merged

Added solution of task 1-9.#3
masterjr86 merged 1 commit intoLesson_2from
Lesson_3

Conversation

@masterjr86
Copy link
Copy Markdown
Owner

No description provided.

Copy link
Copy Markdown

@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.

Оставил комментарии по коду


print(f'Вариант 2. В диапазоне от {N_START} до {N_FINISH}:')
for i in range(START_RANGE, FINISH_RANGE + 1):
answer_1[i] = N_FINISH // i
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Отличные варианты

# Генерация массива, заполненного случайными числами.
array_1 = [rnd.randint(N_MIN, N_MAX) for i in range(SIZE)]
# поиск четных элементов в первом массиве и сохранение их индексов во второй массив
array_2 = [id for id, itm in enumerate(array_1) if not itm % 2]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

not itm % 2 - неявное преобразование целого к логическому.
Перечитайте Дзен Python

N_MIN = 0
N_MAX = 200

array_1 = [rnd.randint(N_MIN, N_MAX) for i in range(SIZE)]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Отлично

elem, expectation = 0, 0 # будет хранить элемент и количесвто таких элементов в массиве

print(array_1)
for i in range(len(array_1)):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Хороший вариант с квадратичной сложностью.

N_MAX = 10000

array_1 = [rnd.randint(N_MIN, N_MAX) for i in range(SIZE)]
max_negative, negative_ind = N_MIN, 0
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

В реальной практике вы можете не знать самый маленький элемент. Ваш алгоритм не универсальный.

max_negative, negative_ind = N_MIN, 0

for id, itm in enumerate(array_1):
if not itm + abs(itm):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

:-(

min_id = id

print(array_1, (elem_min, min_id), (elem_max, max_id))
print(fct.reduce(lambda x, y: x + y, array_1[min_id + 1:max_id]) if min_id < max_id \
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

reduce для суммирования? Забавно.
Именно поэтому Гвидо и убрал функцию в functools. Не нравятся ему программисты, которые суммируют через reduce )))

array_1 = [rnd.randint(N_MIN, N_MAX) for i in range(SIZE)]

min_elem = [array_1[0], array_1[1]]
for i in array_1[2:]:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Т.е. урок вы пропустили? Или считаете нормально для входного массива в 10Гб сделать срез в 10Гб без 8Байт?

column = 5


matrix_test = [[0 for i in range(raws)] for j in range(column)]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍


# генерация матрицы 5х4, заполненной случайными числами
matrix = [[rnd.randint(N_MIN, N_MAX) for _ in range(COLUMN)] for _ in range(RAWS)]
min_elements = [N_MAX] * len(matrix[0])
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

В целом хорошо, но на разбор обязательно приходите

@masterjr86 masterjr86 merged commit e2c3663 into Lesson_2 Mar 10, 2020
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.

2 participants