Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Required 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 please tell me how to proceed?

like image 553
Arohi Gupta Avatar asked Mar 16 '26 13:03

Arohi Gupta


1 Answers

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'}]
like image 147
Pedro von Hertwig Batista Avatar answered Mar 19 '26 01:03

Pedro von Hertwig Batista



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!