0

I know the answer is going to be obvious once I see it, but I can't find how to convert my output list of numbers back to letters after I've manipulated the list.

I am putting in data here:

import string

print [ord(char) - 96 for char in raw_input('Write Text: ').lower()]

and I want to be able to reverse this so after I manipulate the list, I can return it back to letters.

example: input gasoline / output [7, 1, 19, 15, 12, 9, 14, 5]

manipulate the output with append or other then be able to return it back to letters.

Everything I search is only to convert letterst to numbers and nothing to convert that list of numbers back to letters.

Thank you!

Dani Mesejo
  • 61,499
  • 6
  • 49
  • 76
dummy_bear
  • 15
  • 4
  • Look [here](https://stackoverflow.com/questions/227459/how-to-get-the-ascii-value-of-a-character), where a similar question has been answered. – recurvata Apr 07 '20 at 14:31

2 Answers2

0

It can be done by using chr() built-in function :

my_list = [7, 1, 19, 15, 12, 9, 14, 5]
out = ""
for char in my_list:
    out += chr( 96 + char )
print(out) # Prints gasoline
AmirHmZ
  • 516
  • 3
  • 22
0

If you want the final output as a list of characters use the first one otherwise the last one.

l = [7, 1, 19, 15, 12, 9, 14, 5] # l is your list of integers listOfChar = list(map(chr,[x+96 for x in l])) aWord = "".join(list(map(chr,[x+96 for x in l])))#your word here is "gasoline"