Как в список добавить элементы другого списка?
Всем добрый день. Есть 2 списка. Как можно в один список засунуть другой список, но только по одному элементу?
sp_with_follow = ['one', 'two', 'three', 'four', 'five']
res_list = ['1', 2, '3', 4, 5]
for i in range(len(sp_with_follow)):
for cv in sp_with_follow:
res_list.insert(4, cv)
print(res_list)
Вывод:
['1', 2, '3', 4, 'five', 'four', 'three', 'two', 'one', 'five', 'four', 'three', 'two', 'one', 'five', 'four', 'three', 'two', 'one', 'five', 'four', 'three', 'two', 'one', 'five', 'four', 'three', 'two', 'one', 5]
Но как на выходе получить
['1', 2, '3', 4, 'one', 5, '1', 2, '3', 4, 'two', 5, '1', 2, '3', 4, 'three', 5, '1', 2, '3', 4, 'four', 5, '1', 2, '3', 4, 'five', 5]
Ответы (1 шт):
Автор решения: Mamba
→ Ссылка
a = ['one', 'two', 'three', 'four', 'five']
b = ['1', 2, '3', 4, 5]
def very_strange_combine(a, b):
res_list = []
for i in a:
for j in b:
res_list.append(j)
res_list.append(i)
return res_list
print(very_strange_combine(a, b))