I've written the following code to print an upper/lower case alphabet dictionary whose values can be shifted by an integer. It keeps returning only one entry (e.g., {Z:z}), even though when I use a print statement in the for loop, I see the entire dictionary printed as expected, no matter what the shift. Any thoughts on why it would only return one entry would be greatly appreciated?
def dictionary(self, shift):
'''
For Caesar cipher.
shift (integer): the amount by which to shift every letter of the
alphabet. 0 <= shift < 26
Returns: a dictionary mapping a letter (string) to
another letter (string).
'''
#create empty dictionary
alphaDict = {}
#retrieve alphabet in upper and lower case
letters = string.ascii_lowercase + string.ascii_uppercase
#build dictionary with shift
for i in range(len(letters)):
if letters[i].islower() == True:
alphaDict = {letters[i]: letters[(i + shift) % 26]}
else:
alphaDict = {letters[i]: letters[((i + shift) % 26) + 26]}
return alphaDict