-
Notifications
You must be signed in to change notification settings - Fork 6
Homework 2 questions
Klementyna Kasraie edited this page Sep 21, 2017
·
1 revision
There are dedicated tools for doing text processing in python. Check out the 're' package, for example, with functions like re.sub().
However, if you choose to use just base python, here is a hint for approaching this problem (this does not give you the right answer, it is meant to give you one way of thinking about the problem!)
s='abcdefg'
trans = dict(zip(s,range(1,len(s))))
Then, given a word like word="abadag"
you can use a list comprehension for items in s:
".".join([str(trans[letter]) for letter in word])
NOTE: using trans.get()
instead of trans[]
allows you to set a default output value when the key is not found in the dictionary trans.