On Wed, 5 Feb 2020 11:09:16 +0000
Jonathan Fine <[email protected]> wrote:
> How about something like:
>
> >>> def t1(*argv):
> ... value = 0
> ... for n in argv:
> ... value *= 1_000
> ... value += n
> ... return value
>
> >>> t1(123, 456, 789)
> 123456789
>
> Similarly, for define t2 to use 1_000_000, t3 to use 1_000_000_000 and so
> on, instead of 1_000. For really big numbers, you might want to use t10.
Someone previously asked about a "base"; your idea could be extended to
accommodate same:
>>> def tbuilder(base):
def t(*argv):
value = 0
for n in argv:
value *= base
value += n
return value
return t
>>> tbuilder(1000)(123, 456, 789)
123456789
> If you're dealing with really big integers (say 1000 digits or more)
> then you might be want to use https://pypi.org/project/gmpy2/, in
> which case you'll appreciate the extra flexibility provided by
> t10. (This would allow t10 to return a gmpy integer, if import gmpy2
> succeeds.)
+1
> Finally, perhaps really big numbers should be stored as data, rather
> than placed in source code files. (For example, this would allow these
> large pieces of data to be verified, via a secure hash.)
+1
--
“Atoms are not things.” – Werner Heisenberg
Dan Sommers, http://www.tombstonezero.net/dan
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/BY4NM3P3LKUZBL5DQNUHFKEHQJCSPZ3D/
Code of Conduct: http://python.org/psf/codeofconduct/