Sequence splitting

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Fri Jul 3 08:31:42 CEST 2009


En Fri, 03 Jul 2009 01:58:22 -0300, <//phr.cx at nospam.invalid>> escribió:

> "Pablo Torres N." <tn.pablo at gmail.com> writes:
>> def split(seq, func=bool):
>>  	t = filter(func, seq)
>>  	f = filter(lambda x: not func(x), seq)
>>  	return list(t), list(f)
>
> That is icky--you're calling func (which might be slow) twice instead
> of once on every element of the seq.

In addition, this doesn't work if seq is an iterator instead of a sequence.

-- 
Gabriel Genellina




More information about the Python-list mailing list