Need help porting Perl function

Vlastimil Brom vlastimil.brom at gmail.com
Sun Jun 8 15:37:04 EDT 2008


2008/6/7, kj <socyl at 987jk.com.invalid>:
>
>
>
> ... The original Perl function takes a reference to an array, removes
> from this array all the elements that satisfy a particular criterion,
>
> and returns the list consisting of the removed elements. ...
>
>
>
> Just out of curiosity, as I didn't find any mention of filter() in the
suggestions in this thread, I'd like to ask, whether there are some reasons,
why not to use it (or the itertools equivalent); actually it seems to me to
be the simplest way to acomplish the mentioned task (as the solutions not
modifying the original list were proposed too). e.g.:

>>> lst=range(14)
>>> odd = filter(lambda x: x % 2, lst)
>>> even = filter(lambda x: not x % 2, lst)
>>> lst, odd, even

(or a version using itertools.ifilter, ifilterfalse)
Are there maybe some significant performance disadvantages in the two
subsequent implied loops over the input list?

Regards,

   Vlastimil Brom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080608/cddb154b/attachment-0001.html>


More information about the Python-list mailing list