Untitled

mail@pastecode.io avatar
unknown
plain_text
15 days ago
886 B
1
Indexable
Never
# problem_list = [2, 1, 2, 3, 0, 5, 1, 2, 3]
problem_list = [2, 1, 2, 3, 0, 5, 1, 2, 3, 9, 1, 5, 4, 6, 8, 7]

temp_start_index = 0 # 6


def find_higher_in_range(numbers_list, start, finish):
    temp_list = list()
    for i in range(start, finish + 1):
        temp_list.append(numbers_list[i])
    return max(temp_list), numbers_list.index(max(temp_list))


def replace_elements(numbers_list, replace_with, start, finish):
    for i in range(start, finish + 1):
        numbers_list[i] = replace_with

while temp_start_index < len(problem_list):
  temp_higher = find_higher_in_range(problem_list, temp_start_index, len(problem_list) - 1)[0]
  temp_higher_index = find_higher_in_range(problem_list, temp_start_index, len(problem_list) - 1)[1]
  replace_elements(problem_list, temp_higher, temp_start_index, temp_higher_index)
  temp_start_index=temp_higher_index+1

print(problem_list)
Leave a Comment