1
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 these number's chr() is string(alphabet) but how do I convert this list to the alphabet when I print c

c = list(range(chr(97),chr(121)))

It gives an error. So not really sure, how to convert them all at once rather than doing them individually.

imxitiz
  • 3,920
  • 3
  • 9
  • 33
user3382238
  • 143
  • 1
  • 2
  • 11

4 Answers4

2

You should use a list comprehension

c = [chr(i) for i in range(97, 121)]
hivert
  • 10,579
  • 3
  • 31
  • 56
1
intlist = [97, 98, 99, 100, 101, 102, 103, 104, 105, 106]

charlist = [chr(x) for x in intlist]
imxitiz
  • 3,920
  • 3
  • 9
  • 33
machnine
  • 94
  • 8
0

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 ) )]
RymplEffect
  • 151
  • 4
0
intList = [97, 98, 99, 100, 101, 102, 103, 104, 105, 106]
charList = [chr(c) for c in intList]
string = "".join(charList)