Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to change characters in a list to hex numbers?

key = input()

a = list(str(key))
print(a)

Does anyone know how to change that a list to get hex numbers in there? Example:

key = "abc"
>> ["a", "b", "c"]

But instead of those letters hex numbers.

Thanks.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use ord to get the int representation of a character, and hex to get the hex representation of that int.

>>> [hex(ord(c)) for c in "abc"]
['0x61', '0x62', '0x63']
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading