Let's say I have a list of numbers and that I want to "extend" that list to beyond a certain number of elements. How should I extend the list by adding elements that are respectively the mean of the preceding and following element?
numbers = [1, 2, 3, 4, 5]
minimumNumberOfElementsRequired = 15
# do magic here
# first iteration: [1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5]
# second iteration: [1, 1.25, 1.5, 1.75, 2, 2.25, 2.5, 2.75, 3, 3.25, 3.5, 3.75, 4, 4.25, 4.5, 4.75, 5]
# have sufficient number of elements => return list
print(numbers_extended)
# output: [1, 1.25, 1.5, 1.75, 2, 2.25, 2.5, 2.75, 3, 3.25, 3.5, 3.75, 4, 4.25, 4.5, 4.75, 5]
The beginning of my attempt is as follows:
list1 = [1, 2, 3, 4, 5]
list2 = [1, 2, 3, 4, 5]
index = -1
iterator = iter(list1)
for x, y in zip(iterator, iterator):
index += 1
list2.insert(index, (x + y) / float(2))