Rounding up to the nearest exact logarithmic decade
Grant Edwards
grante at visi.com
Tue Feb 28 18:35:50 EST 2006
On 2006-02-28, johnzenger at gmail.com <johnzenger at gmail.com> wrote:
> I like Fredrik's solution. If for some reason you are afraid of
> logarithms, you could also do:
>
>>>> x = 4978
>>>> decades = [10 ** n for n in xrange(-1,8)]
>>>> import itertools
>>>> itertools.ifilter(lambda decade: x < decade, decades).next()
> 10000
>
> BTW, are the python-dev guys aware that 10 ** -1 = 0.10000000000000001 ?
You're joking, right?
--
Grant Edwards grante Yow! HOORAY, Ronald!! Now
at YOU can marry LINDA
visi.com RONSTADT too!!
More information about the Python-list
mailing list