Desired output

I have a list like this

[[{1:"one",2:"two"},{1:"one"}],[{3:"three",4:"four"},{3:"three"}]]

      

required output:

[{1:"one",2:"two"},{1:"one"},{3:"three",4:"four"},{3:"three"}]

      

Can someone tell me how to proceed?

+3


source to share


2 answers


Go through the lists of lists to add them to another list.



list_1 = [[{1:"one",2:"two"},{1:"one"}],[{3:"three",4:"four"},{3:"three"}]]
list_2 = []
for list in list_1:
    for dictionary in list:
        list_2.append(dictionary)

print(list_2)  # [{1: 'one', 2: 'two'}, {1: 'one'}, {3: 'three', 4: 'four'}, {3: 'three'}]

      

+1


source


You can try this:

from itertools import chain

l = [[{1:"one",2:"two"},{1:"one"}],[{3:"three",4:"four"},{3:"three"}]]

new_l = list(chain(*l))

      



Final result:

[{1: 'one', 2: 'two'}, {1: 'one'}, {3: 'three', 4: 'four'}, {3: 'three'}]

      

0


source







All Articles