I have a list made of lists and strings, and I want to extract each element from the list. And if the extracted element is a list, extract the elements from the list.
This is just to manipulate the lists a bit so I don't have anything planned with these items once done, so after that puting them in another list is enought.
for example, i have this list :
meal = [
'salad',
['coquillette', 'ratatouille', 'steak'],
'cheese', ['ice cream', 'tart', 'fruit']
]
and I want :
dishes = [
'salad',
'coquillette',
'ratatouille',
'steak',
'cheese',
'ice cream',
'tart',
'fruit'
]
for the moment I have done this :
meal = ['salad', ['coquillette', 'ratatouille', 'steak'], 'cheese', ['ice cream', 'tart', 'fruit']]
dishes = []
for dish in meal:
for item in dish:
if isinstance(dish, list):
dishes.append(item)
#print(item)
else:
dishes.append(dish)
#print(dish)
print(dishes)
but I get :
[
'salad',
'coquillette',
'ratatouille',
'steak',
**['coquillette', 'ratatouille', 'steak']**,
'cheese',
'ice cream',
'tart',
'fruit',
**['ice cream', 'tart', 'fruit']**
]
any advices ?