Stackoverflow, hello
I have a specific task now. It concerns a uniting elements into a list and also checking for a lower letter.
So, I have a hierarchical list with lists inside:
ingridient_names_final=[['Egg', 'Milk', 'Tomato'], ['Duck', 'Water', 'Honey', 'Soy', 'sauce'], ['Potato', 'Garlic', 'Gouda', 'cheese'], ['Beef', 'Sweet', 'pepper', 'Pita', 'bread', 'Wine', 'vinegar', 'Tomato']]
Which should be transformed to:
[['Egg', 'Milk', 'Tomato'], ['Duck', 'Water', 'Honey', 'Soy sauce'], ['Potato', 'Garlic', 'Gouda cheese'], ['Beef', 'Sweet pepper', 'Pita bread', 'Wine vinegar', 'Tomato']]
So, words "sause", "cheese", "pepper", "bread" and "vinegar" I need to join to the previous element of the list.
I understood only that method islower()
should be used here:
for element in ingridient_names_final:
# print (element)
for element2 in element:
# print (element2)
if element2.islower():
print(element2)
An the result is:
sauce
cheese
pepper
bread
vinegar
But how can I join them to the previous element of the each small list inside the original one? I am a beginner in this language, please, help)