2008/6/7, kj <[EMAIL PROTECTED]>:
>
>
>
> ... 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
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to