[Tutor] Break element into list while iterating

Julius Hamilton juliushamilton100 at gmail.com
Sat Dec 25 12:11:26 EST 2021


Hey,

I would like to do some kind of list comprehension where elements meeting
certain conditions get split on a delimiter. They don’t become lists nested
in one element in the previous list; the new elements just get inserted
where the old one was.

Like this:

[“apple”, “pear”]

->

[“a”, “p”, “p”, “l”, “e”, “pear”]

Is there a list comprehension syntax where if I split an element with
e.split(), I can “insert” those elements at the element they came from?

Thanks very much,
Julius


More information about the Tutor mailing list