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?

有帮助吗?

解决方案

map(hex,map(int, a))

or perhaps

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

depending on what you are trying to do ...

其他提示

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

In [99]: [hex(int(i)) for i in a]
Out[99]: ['0xc', '0x22']
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top