Your current version using two separate list comprehensions can be simplified to use a single list comprehension instead:
lst = [e for elem in lst for e in elem.split()]
But, if you want to use a traditional for
loop instead, then you can loop through each elem
of lst
as you currently do, and use list.extend()
to add the splitted elements to a result list res
:
lst = ["Mi Fa Sol", 'Mi', "Mi Fa Sol La Si", "Do Si", " Mi Si Fa", "Fa"]
res = []
for elem in lst:
res.extend(elem.split())
print(res)
Output:
['Mi', 'Fa', 'Sol', 'Mi', 'Mi', 'Fa', 'Sol', 'La', 'Si', 'Do', 'Si', 'Mi', 'Si', 'Fa', 'Fa']
You can assign res
back to lst
if needed afterwards.
Side note: since you use the default delimiter for split()
, you can also omit the redundant strip()
in this case.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…