get a list printed in hexadecimal notation

Bengt Richter bokr at oz.net
Thu Jul 18 14:42:49 EDT 2002


On Thu, 18 Jul 2002 09:39:56 +0200, Oliver Eichler <oliver.eichler at dspsolutions.de> wrote:

>
>Another tip I received from Harvey Thomas & François Pinard:
>
>print  [isinstance(x,int) and hex(x) or x for x in l]
>
That's fine if this is acceptable:

 >>> l = ('spam',10,15,'more spam',['nested',65535,'spam'],'spam',255)
         ^                                   ^^^^^                   ^
 >>> print  [isinstance(x,int) and hex(x) or x for x in l]
 ['spam', '0xa', '0xf', 'more spam', ['nested', 65535, 'spam'], 'spam', '0xff']
 ^                                              ^^^^^                         ^

Regards,
Bengt Richter



More information about the Python-list mailing list