Question: I have a list that is the `a=[0,1]` and I want to change with `a=[0x00,0x001]` type. How can I do this? I tried this way 

```
print (struct.pack('>h',a))

```

But I cannot change to hex

Answer: 
Using [hex(...)](https://docs.python.org/3/library/functions.html#hex) will only give you the least amount of leading 0:

```
print( [hex(i) for i in [0,1]])  #  ['0x1', '0x2']

```

You can [format(...)](https://docs.python.org/3/library/functions.html#format) the string as hex and [zfill()](https://docs.python.org/3/library/stdtypes.html#str.zfill) the needed amount of zeros and prepending `'0x'` to it yourself:

```
data = [0,1]

as_hex = [ "0x" + format(e,"x").zfill(2) for e in data]

print(as_hex)

```

Output:

```
['0x00', '0x01']

```
Below is the another way of converting you list of integer to list of hex

```
a = [0,1]
b = map(hex, a) 
# or 
b = map(lambda x:hex(x), a)
# output
print b
['0x1', '0x2']

```