I'm trying to create a dictionary by pulling from a text file that looks something like this,
Fred beats Amy
Fred beats Tom
Tom beats Amy
Amy beats Jordan
Right now I'm using
f = open("RockPaperScissors.txt", 'r')
fwDict = {}
for line in f:
k, v = line.strip().split('beats')
fwDict[k.strip()] = v.strip()
f.close()
The problem I'm running into is that when "Fred" appears multiple times it just overwrites the previous value (Amy) and replaces it with the newest one (Tom), is there any way I can just add a new value if the key already exists, even when pulling from a txt file?
Thanks!