Question

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?

Was it helpful?

Solution

map(hex,map(int, a))

or perhaps

map(lambda x:int(x,16),a)

depending on what you are trying to do ...

OTHER TIPS

or a list comprehension aside from @Joran's answer:

In [99]: [hex(int(i)) for i in a]
Out[99]: ['0xc', '0x22']
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top