Possible to append multiple lists at once? (Python)
x.extend(y+z)
should do what you want
or
x += y+z
or even
x = x+y+z
Extending my comment
In [1]: x = [1, 2, 3]
In [2]: y = [4, 5, 6]
In [3]: z = [7, 8, 9]
In [4]: from itertools import chain
In [5]: print list(chain(x,y,z))
[1, 2, 3, 4, 5, 6, 7, 8, 9]
You can use sum
function with start value (empty list) indicated:
a = sum([x, y, z], [])
This is especially more suitable if you want to append an arbitrary number of lists.
To exactly replicate the effect of append, try the following function, simple and effective:
a=[]
def concats (lists):
for i in lists:
a==a.append(i)
concats ([x,y,z])
print(a)