Отредактировано ради простоты, так как я указал, что проблема указывает на «распаковку аргументов».
Я пытаюсь написать функцию, которая чередует произвольное количество списков в качестве параметров. Все списки имеют одинаковую длину. Функция должна возвращать один список, содержащий все элементы из чередующихся входных списков.
def interleave(*args):
for i, j, k in zip(*args):
print(f"On {i} it was {j} and the temperature was {k} degrees celsius.")
interleave(["Monday Tuesday Wednesday Thursday Friday Saturday Sunday".split()],["rainy rainy sunny cloudy rainy sunny sunny".split()],[10,12,12,9,9,11,11])
Вывод:
On ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] it was ['rainy', 'rainy', 'sunny', 'cloudy', 'rainy', 'sunny', 'sunny'] and the temperature was 10 degrees celsius.
желаемый вывод:
On Monday it was rainy and the temperature was 10 degrees celsius.
On Tuesday it was rainy and the temperature was 12 degrees celsius.
On Wednesday it was sunny and the temperature was 12 degrees celsius.
On Thursday it was cloudy and the temperature was 9 degrees celsius.
On Friday it was rainy and the temperature was 9 degrees celsius.
On Saturday it was sunny and the temperature was 11 degrees celsius.
On Sunday it was sunny and the temperature was 11 degrees celsius.