char list from 0 to f

0 votes
I write a python script, which needs a list of all hexadecimal characters.

Is it a good idea to do list(string.printable[:16]) to get ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'] ?
Jul 15, 2019 in Python by ana1504.k
• 7,890 points
52 views

1 answer to this question.

0 votes

The simplest way would be a list comprehension of all numbers from 0 to 15 formatted as hex:

["{:x}".format(x) for x in range(0,16)]

User GarbageCollector suggested a nice alternative in comments, which must be adapted to remove the redundant, uppercased chars:

>>> import string
>>> string.hexdigits
'0123456789abcdefABCDEF'
>>> string.hexdigits[:16]
'0123456789abcdef'

to get a list:

>>> list(string.hexdigits[:16])
answered Jul 15, 2019 by SDeb
• 13,250 points

Related Questions In Python

0 votes
1 answer

How to create Pandas dataframe from Python list?

You can do it like this: import ...READ MORE

answered Apr 5, 2019 in Python by Likhita
296 views
+1 vote
1 answer

How to convert records from csv to a list in Python?

If you are using Python 3.x then ...READ MORE

answered Jun 25, 2019 in Python by Arvind
• 2,980 points

edited Jun 26, 2019 by Kalgi 886 views
0 votes
0 answers

How to remove elements from a list that may or may not be present?

In case I want to remove some ...READ MORE

Jun 27, 2019 in Python by Nisa
• 1,090 points
102 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,081 views
0 votes
0 answers
0 votes
1 answer

How to Reverse a list in Python

You can use the reversed function in ...READ MORE

answered Sep 28, 2018 in Python by SDeb
• 13,250 points
150 views
0 votes
1 answer

How to exit from Python without traceback?

You are presumably encountering an exception and ...READ MORE

answered Oct 9, 2018 in Python by SDeb
• 13,250 points
254 views