I tried to test the performance of list comprehension and map. I did not see much difference
Here is my test localhost% python -mtimeit -s"sum(int(i) for i in '3245325')" 10000000 loops, best of 3: 0.02 usec per loop localhost% python -mtimeit -s"sum(map(int, str(3245325)))" 10000000 loops, best of 3: 0.02 usec per loop Thanks On Thu, May 9, 2013 at 3:30 PM, <[email protected]> wrote: > Send BangPypers mailing list submissions to > [email protected] > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.python.org/mailman/listinfo/bangpypers > or, via email, send a message with subject or body 'help' to > [email protected] > > You can reach the person managing the list at > [email protected] > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of BangPypers digest..." > > > Today's Topics: > > 1. [Ticket #49] Another qn. THanks for the basic of basic qn\ > (Prashant R. Naik) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Thu, 9 May 2013 08:23:48 +0000 > From: "Prashant R. Naik" <[email protected]> > To: "[email protected]" <[email protected]> > Subject: [BangPypers] [Ticket #49] Another qn. THanks for the basic of > basic qn\ > Message-ID: > <[email protected]> > Content-Type: text/plain; charset="us-ascii" > > On May 09, 2013 @ 01:51 pm, bangpypers-bounces+prashant= > [email protected] wrote: > > On 8 May 2013 23:00, Jagadeesh N. Malakannavar <[email protected]> > wrote: > > I prefer to do it like this > > > >>>> a = list(str(3245325)) > >>>> sum(map(int, a)) > > 24 > > What does the map() gain you over basic list comprehension: > sum( [int(i) for i in '3245325'] ) > ignoring any try/catch for int conversion errors > > IMHO, this is easier to understand, more Pythonic, and likely > faster. > > Regards, > Gora > _______________________________________________ > BangPypers mailing list > [email protected] > http://mail.python.org/mailman/listinfo/bangpypers > > ________________________________ > This is an automated response. Your issue has been noted. We'll be in > touch soon. > > Please reply to this email or visit the URL below with any additional > details. > > http://DB01:9675/portal/view-help-request/49 > > > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > BangPypers mailing list > [email protected] > http://mail.python.org/mailman/listinfo/bangpypers > > > ------------------------------ > > End of BangPypers Digest, Vol 69, Issue 8 > ***************************************** > -- Thanks, Jagadeesh N.Malakannavar _______________________________________________ BangPypers mailing list [email protected] http://mail.python.org/mailman/listinfo/bangpypers
