Use list.extend()
, not list.append()
to add all items from an iterable to a list:
l.extend(t)
l.extend(t2)
or
l.extend(t + t2)
or even:
l += t + t2
where list.__iadd__
(in-place add) is implemented as list.extend()
under the hood.
Demo:
>>> l = []
>>> t = (1,2,3)
>>> t2 = (4,5)
>>> l += t + t2
>>> l
[1, 2, 3, 4, 5]
If, however, you just wanted to create a list of t + t2
, then list(t + t2)
would be the shortest path to get there.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…