Pruss Manifesto - Long numbers

Mel Wilson mwilson at the-wire.com
Tue Nov 11 15:58:54 CET 2003


In article <2259b0e2.0311101009.59a5ed2e at posting.google.com>,
mis6 at pitt.edu (Michele Simionato) wrote:
>> Georgy Pruss wrote:
>> 1) Underscores in numbers. It will help to read long numbers.
>> E.g.
>>    12 345 678
>>    3.14159 26535 89793 23846
>
>Typically, long numbers are not in the program code, but in an
>external data file. Then, they can be read as strings and converted
>to numbers with a one-liner:
>
>>>> def i(x): return int(x.replace(" ",""))
>...
>>>> i("1 234")
>1234
>
>So, this "feature" is not worth the effort, IMHO.

   Except in some cryptological code, e.g.  DES, Blowfish.
But the 'i' solution works just as well inside a program.

    def h (s): return int (s.replace ('_', ''), 16)

    def ks0tbl ():
        return map (h, (
            'd131_0ba6', '98df_b5ac', '2ffd_72db', 'd01a_dfb7',
[page (printed, not screen) of hex constants]
            '53b0_2dfd', 'a99f_8fa1', '08ba_4799', '6e85_076a'
        ))

    ks0 = ks0tbl()
    del ks0tbl



        Regards.        Mel.




More information about the Python-list mailing list