-2

I have a list that looks similar to:

list = [[[a,b,c], e, f, g], h, i, j]

and my desired output is:

merged_list = [a,b,c,e,f,g,h,i,j]

does anyone know an efficient way to do this?

i tried to do some sort of merging lists with the sum function but it didn't work

Psytho
  • 3,313
  • 2
  • 19
  • 27
VicMoo
  • 1

1 Answers1

0

first i make all your variable into string because it was giving me error of not defined

so here is the code

#you have 3 list in total
list = [[['a','b','c'], 'e', 'f', 'g'], 'h', 'i', 'j']

output_list = [] # created a empty list for storing the all data in list

for list2 in list: # you will get 2 list now
    for list1 in list2:# you will get 1 list now
        for i in list1: # now you will only have items in list
            output_list.append(i) #adding all item in output_list one by one
print(output_list)   # printing the list     

CYCNO
  • 88
  • 8