split up a list by condition?
Reinhold Birkenfeld
reinhold-birkenfeld-nospam at wolke7.net
Tue Jun 7 15:20:11 EDT 2005
Duncan Booth wrote:
> Reinhold Birkenfeld wrote:
>
>> Hi,
>>
>> 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? Such as
>>
>> vees, cons = split(wlist[::-1], lambda c: c in vocals)
>>
>> Reinhold
>
> If you really are being charged by the number of newline characters in your
> code you could write:
[...]
> but every penny you save writing a one liner will be tuppence extra on
> maintenance.
This is clear. I actually wanted to know if there is a function which I
overlooked which does that, which wouldn't be a maintenance nightmare at all.
Reinhold
More information about the Python-list
mailing list