Pair = 'A' elif i == 1: Pair = 'E' elif i == 2: Pair = 'U'Here you assign a string to Pair and not the dictionary you want to work with. This means your code really does:
'A'['Bi'] = Pair + 'b' # when it should be A['Bi'] = Pair + 'b'So instead just remove the parentheses from A E and U.