Skip to content Skip to sidebar Skip to footer

How Do I Convert A List Of Numbers Into Their Corresponding Chr()

c = list(range(97, 121)) if i print this it will give [97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119] each of

Solution 1:

You should use a list comprehension

c = [chr(i) for i in range(97, 121)]

Solution 2:

intlist = [97, 98, 99, 100, 101, 102, 103, 104, 105, 106]

charlist = [chr(x) for x in intlist]

Solution 3:

hivert's solution is really good if you want to convert a range of numbers into characters, but if you have a pre-existing list of integers that you want to convert into characters, you could adapt the solution like this:

intList = [97, 98, 99, 100, 101, 102, 103, 104, 105, 106]
charList = [chr( intList[i] ) for i in range( 0, len( intList ) )]

Solution 4:

intList = [97, 98, 99, 100, 101, 102, 103, 104, 105, 106]
charList = [chr(c) for c in intList]
string = "".join(charList)

Post a Comment for "How Do I Convert A List Of Numbers Into Their Corresponding Chr()"