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 please tell me how to proceed?
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 please tell me how to proceed?
Iterate over the list's lists to add that 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'}]
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 Output:
[{1: 'one', 2: 'two'}, {1: 'one'}, {3: 'three', 4: 'four'}, {3: 'three'}]