Possible Duplicate:
Flattening a shallow list in Python
Making a flat list out of list of lists in Python
Merge two lists in python?
Fast and simple question:
How do i merge this.
[['a','b','c'],['d','e','f']]
to this:
['a','b','c','d','e','f']
In python, we can use the + operator to merge the contents of two lists into a new list. For example, We can use + operator to merge two lists i.e. It returned a new concatenated lists, which contains the contents of both list_1 and list_2.
Using list comprehension:
ar = [['a','b','c'],['d','e','f']] concat_list = [j for i in ar for j in i]
list concatenation is just done with the +
operator.
so
total = [] for i in [['a','b','c'],['d','e','f']]: total += i print total
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