I am trying to manipulate user input strings using the ord() funtion. This effectively allows me to identify the decimal value of each character in the string. I have been able to return the value of the characters, but what I need to understand is how to store each value (to manipulate it), and how to return the characters associated with the new values.

In essence, the user inputs :


and the return is


I want to store these values, then manipulate them:


then returns:

Fun with ascii values of a string ...

def ascii_list(s):
    """return a list of ascii values of the characters in string s"""
    return [ord(c) for c in s]

s = 'cat'
alist = ascii_list(s)
print alist  # [99, 97, 116]

# manipulate the list elements
alist[0] += 1
alist[1] += 14
alist[2] -= 13

# convert ascii to char
clist = [chr(e) for e in alist]
# join to form a word
print "".join(clist)  # dog

Extremely helpful, thanks for the post! And finally the use of char() sinks into my thick skull.

I'm greatful to all your contributions.