Append multiple lists Python
Simple example code appends elements of 2-3 lists to one list.
l1 = [1, 3, 5, 5, 4] l2 = [4, 6, 2, 8, 10] l3 = [7, 5, 2, 9, 11] # Using + operator res1 = l1 + l2 + l3 print(res1) # Using itertools.chain() from itertools import chain res2 = list(chain(l1, l2, l3)) print(res2) # With zip res_list = list(zip(l1, l2, l3)) print(res_list)
Possible to append multiple lists at once?
Answer: yes this is possible using extend function.
x += y+z
x = x+y+z
If you prefer a slightly more functional approach, you could try:
import functools as f x = [1, 2, 3] y = [4, 5, 6] z = [7, 8, 9] x = f.reduce(lambda x, y: x+y, [y, z], x)
Do comment if you have any doubts or suggestions on this Python list topic.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.