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, <bangpypers-requ...@python.org> wrote: > Send BangPypers mailing list submissions to > bangpypers@python.org > > 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 > bangpypers-requ...@python.org > > You can reach the person managing the list at > bangpypers-ow...@python.org > > 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" <prash...@triconinfotech.com> > To: "bangpypers@python.org" <bangpypers@python.org> > Subject: [BangPypers] [Ticket #49] Another qn. THanks for the basic of > basic qn\ > Message-ID: > <E728B7F635D6814A9049AC1C56B08D0C473F11B5@MAIL.triconhome.local> > Content-Type: text/plain; charset="us-ascii" > > On May 09, 2013 @ 01:51 pm, bangpypers-bounces+prashant= > triconinfotech....@python.org wrote: > > On 8 May 2013 23:00, Jagadeesh N. Malakannavar <mnjagade...@gmail.com> > 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 > BangPypers@python.org > 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 > BangPypers@python.org > http://mail.python.org/mailman/listinfo/bangpypers > > > ------------------------------ > > End of BangPypers Digest, Vol 69, Issue 8 > ***************************************** > -- Thanks, Jagadeesh N.Malakannavar _______________________________________________ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers