Splitting lists
Ben Wolfson
wolfson at uchicago.edu
Wed Feb 26 23:38:57 EST 2003
On Thu, 27 Feb 2003 04:10:17 +0100, Ferenczi Viktor wrote:
> Are there any fast, simple and elegant method to split a list by a filter
> function?
>
> My current solutions with their shortcomings:
> # Solution 2:
> tl=[]
> fl=[]
> for e in lst:
> if fn(e): tl.append(e)
> else: fl.append(e)
> # Relatively slow
I don't know why you call this one relatively slow; on my system, it's
faster than the other two--which stands to reason, since the list is only
traversed once and the function is only called n times.
--
I certainly seem to be enjoying myself in the same way, smacking my
lips, sighing and moaning, dripping [REDACTED] on my shirt and
smearing it into my moustache ... But ... If I snuck a lick of your
cone, I wouldn't smack my lips. -- Ted Cohen
More information about the Python-list
mailing list