Given lists = [['hello'], ['world', 'foo', 'bar']]
How do I transform that into a single list of strings?
combinedLists = ['hello', 'world', 'foo', 'bar']
Python merges two lists without duplicates could be accomplished by using a set. And use the + operator to merge it.
Concatenate Two Lists in Python In almost all simple situations, using list1 + list2 is the way you want to concatenate lists.
lists = [['hello'], ['world', 'foo', 'bar']] combined = [item for sublist in lists for item in sublist]
Or:
import itertools lists = [['hello'], ['world', 'foo', 'bar']] combined = list(itertools.chain.from_iterable(lists))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With