I am trying to output the alphabetical values of a user entered string, I have created a dict and this process works, but only with one letter.
- If I try entering more than one letter, it returns a
KeyError: (string I entered)
- If I try creating a list of the string so it becomes
['e', 'x', 'a', 'm', 'p', 'l', 'e']
and I get aTypeError: unhashable type: 'list'
I cannot use the chr
and ord
functions (I know how to but they aren't applicable in this situation) and I have tried using the map
function once I've turned it to a list but only got strange results.
I've also tried turning the list
into a tuple
but that produces the same error.
Here is my code:
import string
step = 1
values = dict()
for index, letter in enumerate(string.ascii_lowercase):
values[letter] = index + 1
keyw=input("Enter your keyword for encryption")
keylist=list(keyw)
print(values[keylist])
Alt version without the list:
import string
step=1
values=dict()
for index, letter in enumerate(string.ascii_lowercase):
values[letter] = index + 1
keyw=input("Enter your keyword for encryption")
print(values[keyw])