Mots clés : pythonlistconcatenationpython
96
listone = [1, 2, 3] listtwo = [4, 5, 6] joinedlist = listone + listtwo
>>> joinedlist [1, 2, 3, 4, 5, 6]
87
>>> l1 = [1, 2, 3] >>> l2 = [4, 5, 6] >>> joined_list = [*l1, *l2] # unpack both iterables in a list literal >>> print(joined_list) [1, 2, 3, 4, 5, 6]
l = [1, 2, 3] r = range(4, 7) res = l + r
res = [*l, *r]
79
import itertools for item in itertools.chain(listone, listtwo): # Do something with each list item
68
listone = [1,2,3] listtwo = [4,5,6] listone.extend(listtwo)
mergedlist = [] mergedlist.extend(listone) mergedlist.extend(listtwo)
55
mergedlist = list(set(listone + listtwo))