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,910 points
581 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,300 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 6, 2019 in Python by Likhita
1,289 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
• 3,050 points

edited Jun 26, 2019 by Kalgi 9,851 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
797 views
0 votes
2 answers
+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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,434 views
0 votes
1 answer
0 votes
1 answer

How to Reverse a list in Python

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

answered Sep 29, 2018 in Python by SDeb
• 13,300 points
843 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,300 points
1,094 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP