split up a list by condition?
Raymond Hettinger
python at rcn.com
Tue Jun 7 02:30:02 EDT 2005
>> while writing my solution for "The python way?", I came across this fragment:
>> vees = [c for c in wlist[::-1] if c in vocals]
>> cons = [c for c in wlist[::-1] if c not in vocals]
>>
>> So I think: Have I overlooked a function which splits up a sequence
>> into two, based on a condition
Trying to compress too much into one line is not "the python way" ;-)
vees, cons = [], []
for c in reversed(wlist):
if c in vocals:
vees.append(c)
else:
cons.append(c)
More information about the Python-list
mailing list