On Thu, Jul 15, 2010 at 9:50 AM, Srinivas Reddy Thatiparthy <
srinivas_thatipar...@akebonosoft.com> wrote:

> I read from Python 2.6.3 docs that,copied from chm....
>
> " Note that filter(function, iterable) is equivalent to [item for item in
> iterable if function(item)] if function is not None and [item for item in
> iterable if item] if function is None."
>
> Since they said *equivalent* ,i thought both transform to same byte code.I
> missed the point that they are equal *logically*.
>

Never - "filter", "map" etc are implemented as functions so each
call involve a function call in Python which is costly. List comprehensions
are implemented in the language and hence much more optimized.

So if you are aiming to extract maximum juice from your Python
code, prefer native language constructs like comprehensions
as opposed to "outsiders" like map, filter etc. If required, always
prefer the itertools version of these functions such as itertools.imap
etc.


>
>
>
> Regards,
> Srini T.
> --
>
>
> _______________________________________________
> BangPypers mailing list
> BangPypers@python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>
>


-- 
--Anand
_______________________________________________
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers

Reply via email to