This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients
Date 2004-10-27.06:24:16
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
Logged In: YES 
user_id=80475

Nice simplification.
Checked in with minor modifications:
* reduce() replaced with clearer, faster for-loop (see
timings below)
* chain of ifs covered distinct cases, so used if-elif-else
to avoid  unnecessary tests.

See Lib/decimal.py 1.30

----- Timing of for-loop vs reduce() with lambda --------

>>> min(Timer(s1, setup).repeat(9, 1000))
0.039173469216714996
>>> min(Timer(s1, setup).repeat(9, 100000))
3.8988694078010013
>>> min(Timer(s2, setup).repeat(9, 100000))
2.2458371746090293
>>> s1
'cum = reduce(lambda x,y: 10*x+y, val)'
>>> s2
'\ncum = 0\nfor dig in val:\n    cum = cum * 10 + dig\n'
>>> setup
'\nval = [9,6,1,2,3,0,2,4,1,5,7,1,5,6,9]\n'
History
Date User Action Args
2007-08-23 15:40:20adminlinkissue1053375 messages
2007-08-23 15:40:20admincreate