Этот подробный параметр работает также, если -1
больше len(a
):
a=[2,4,6]
b=[1,3,5,-1,-1,-1,-1]
def replace(iterable, replacements):
i = 0
for e in iterable:
if e == -1 and i < len(replacements):
yield replacements[i]
i += 1
else:
yield e
res = sorted(replace(b, a))
print(res) #=> [-1, 1, 2, 3, 4, 5, 6]