map(hex,map(int, a))
or perhaps
map(lambda x:int(x,16),a)
depending on what you are trying to do ...
Domanda
I have list like this: a = ['12', ''34]
. Now I want to convert to a list of hexadecimals by using map
, how to do that?
I mean, if I tried to convert it to a list of decimals, then I would do map(int, a)
. Now what is its equivalent code to convert it in hex?
Soluzione
map(hex,map(int, a))
or perhaps
map(lambda x:int(x,16),a)
depending on what you are trying to do ...
Altri suggerimenti
or a list comprehension aside from @Joran's answer:
In [99]: [hex(int(i)) for i in a]
Out[99]: ['0xc', '0x22']