I'm iterating over a list of tuples and a list of strings. The strings are identifiers for the items in the list. I have a dictionary that has the strings identifiers as keys and has an initially empty list for each value. I want to append something from the tuple list to each key. A simplified version of what I'm doing is:
tupleList = [("A","a"),("B","b")]
stringList = ["Alpha", "Beta"]
dictionary = dict.fromkeys(stringList, []) # dictionary = {'Alpha': [], 'Beta': []}
for (uppercase, lowercase), string in zip(tupleList, stringList):
dictionary[string].append(lowercase)
I would expect this to give dictionary = {'Alpha': ['a'], 'Beta': ['b']}, but instead I find that {'Alpha': ['a', 'b'], 'Beta': ['a', 'b']}. Does anyone have any idea what I'm doing wrong?
