Menggabungkan daftar daftar ke daftar tunggal Python
import itertools
a = [['a','b'], ['c']]
print(list(itertools.chain.from_iterable(a)))
Sparkling Sable
import itertools
a = [['a','b'], ['c']]
print(list(itertools.chain.from_iterable(a)))
sample_list1 = [0, 1, 2, 3, 4]
sample_list2 = [5, 6, 7, 8]
result = sample_list1 + sample_list2
print ("Concatenated list: " + str(result))
list1 = ["Hello ", "take "]
list2 = ["Dear", "Sir"]
resList = [x+y for x in list1 for y in list2]
print(resList)
#['Hello Dear', 'Hello Sir', 'take Dear', 'take Sir']
x = [["a","b"], ["c"]]
result = sum(x, [])
listone = [1, 2, 3]
listtwo = [4, 5, 6]
joinedlist = listone + listtwo
sum([[1, 2, 3], [4, 5, 6], [7], [8, 9]],[])
# [1, 2, 3, 4, 5, 6, 7, 8, 9]