Dumb python questions

Andrew Dalke dalke at acm.org
Sun Aug 19 01:38:58 EDT 2001


Paul Rubin:
>  It's kind of a strange idea though, that
>Python has built-in long ints but I have to use an add-on package if I
>want to do simple operations like find out how large a number is.

Now my chance to ask a dumb question.  When do you need to know
how many bits are used for a number?  I admit to never needing
that functionality, but then again, I've almost never used long
integers in real code.

Though the very first Python code I wrote was something like:

primes = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29)

def godel(s):
  n = 1L
  for i in range(len(s)):
    n = n * long(primes[i])**(ord(s[i])-ord("A")+1)
  return n

so "CAB" == 600L
"ANDREW" == 65468565968763894209893994715140738242806825295981758750L

(because of the fundamential theorem of algebra -- prime factorization
is unique -- this number can be turned back into its original value).

                    Andrew
                    dalke at dalkescientific.com







More information about the Python-list mailing list