How flatten a nested list of strings using two list compehension

Viewed 15

I have the next list with strings and a nested list inside. And I want to use two list comprehension to flat it:

I am trying to use two nested list comprehension :

tweet_list=['!iniciamos', 'la',    ['mi', 'banco', 'banco', 'señal'],  'con', 'nuestro', 'invitado', 'especial']
flat=[]
flated_list= [[flat.append(sub_elem) for sub_elem in elem] if isinstance(elem,list) else flat.append(elem) for elem in tweet_list]

I am getting two nest lists of Nones. How could I fix it?

1 Answers
out = [vv for v in tweet_list for vv in ([v] if isinstance(v, str) else v)]
print(out)

Prints:

['!iniciamos', 'la', 'mi', 'banco', 'banco', 'señal', 'con', 'nuestro', 'invitado', 'especial']
Related