How convert string '1e7' to an integer?

Mick Krippendorf mad.mick at gmx.de
Sun Nov 8 08:39:05 EST 2009


Thomas wrote:
> Just a curiosity, why does Python do this?
> 
>>>> [(base, int('1e7', base=base)) for base in range(15,37)]
> [(15, 442), (16, 487), (17, 534), (18, 583), (19, 634), (20, 687),
> (21, 742), (22, 799), (23, 858), (24, 919), (25, 982), (26, 1047),
> (27, 1114), (28, 1183), (29, 1254), (30, 1327), (31, 1402), (32,
> 1479), (33, 1558), (34, 1639), (35, 1722), (36, 1807)]
>>>> ([base, int('1e7', base=base)] for base in range(15,37))
> <generator object at 0x027803A0>
Because the former is a list comprehension, whereas the latter is a
generator expression.

Mick.



More information about the Python-list mailing list