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 ?

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to