Home > front end >  Create a single which contains string and list
Create a single which contains string and list

Time:04-16

I have one list

list1 = [['abc'], 'xyz', 'jhg', ['uvw', 'cde']]

with this list1 we need to create another list as shown below

list1 = ['abc', 'xyz', 'jhg', 'uvw', 'cde']

I am new in python please help

CodePudding user response:

This simple looping logic can do the trick:

final_list = []
for item in list1:
     if type(item)==list:
          final_list  = item
     else:
          final_list.append(item)
  • Related