Вопрос

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