Reputation: 11
I have the following lista that contains lists and strings:
[['i','love','you'],['i','like','you']]
I would like to make it a list with this output:
["i love you", "i like you"]
Probably I might not be using the correct keywords to find the desired answer(Using python).how to solve this?
Upvotes: 0
Views: 63
Reputation: 57033
The same function as in the other answer, but uses mapping:
strings = [['i','love','you'],['i','like','you']]
list(map(" ".join, strings))
#['i love you', 'i like you']
Upvotes: 0
Reputation: 6441
You can use .join()
to flatten a single list into a string. Then use list comprehension to iterate over all the lists.
inp = [['i','love','you'],['i','like','you']]
outp = [' '.join(i) for i in inp]
print(outp)
>>> ['i love you', 'i like you']
Upvotes: 3