I have a txt file that contain the following:
Monday, 56
Tuesday, 89
Wednesday, 57
Monday, 34
Tuesday, 31
Wednesday, 99
I need it to be converted to a dictionary:
{'Monday': [56 , 34], 'Tuesday': [89, 31], 'Wednesday': [57, 99]}
Here is the code I have so far:
d = {}
with open("test.txt") as f:
for line in f:
(key, val) = line.split()
d[str(key)] = val
print(d)
And here is the result I get from it:
{'Monday,': '56'}
{'Monday,': '56', 'Tuesday,': '89'}
{'Monday,': '56', 'Tuesday,': '89', 'Wednesday,': '57'}
{'Monday,': '34', 'Tuesday,': '89', 'Wednesday,': '57'}
{'Monday,': '34', 'Tuesday,': '31', 'Wednesday,': '57'}
{'Monday,': '34', 'Tuesday,': '31', 'Wednesday,': '99'}
Can anyone help me with this?
Thanks