I have the following code:
list1 = [['a','b','c'],['d','e','f'],['g','h','i']]
sentences = []
for row in list1:
for i in row:
sentences.append(i)
print(sentences)
With the output:
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']
How can I write that in one sentence? This is what I tried:
sentences = [i for i in row for row in list1]
print(sentences)
This is what I got:
['g', 'g', 'g', 'h', 'h', 'h', 'i', 'i', 'i']