map is useless!
Shashwat Anand
anand.shashwat at gmail.com
Sun Jun 6 13:08:20 EDT 2010
map is not needed. LC is great :D
On Sun, Jun 6, 2010 at 10:32 PM, Alain Ketterlin <
alain at dpt-info.u-strasbg.fr> wrote:
> rantingrick <rantingrick at gmail.com> writes:
>
> > Python map is just completely useless. [...]
>
> >>>> import time
> >>>> def test1():
> > l = range(10000)
> > t1 = time.time()
> > map(lambda x:x+1, l)
> > t2= time.time()
> > print t2-t1
> >>>> def test2():
> > l = range(10000)
> > t1 = time.time()
> > for x in l:
> > x + 1
> > t2 = time.time()
> > print t2-t1
> >
> >>>> test1()
> > 0.00200009346008
> >>>> test2()
> > 0.000999927520752
> >>>> def test3():
>
> Well, not building the resulting list saves some time. But even if you
> do r.append(x+1) map appears to be slower...
>
> Try this:
>
> def test3():
> l = range(10000)
> t1 = time.time()
> [ x+1 for x in l]
> t2 = time.time()
> print t2-t1
>
> I've not used map since I learned about list comprehensions.
>
> -- Alain.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100606/7bef72d3/attachment-0001.html>
More information about the Python-list
mailing list