python: creating a list inside a dictionary
- by user1871081
I just started using python and I'm trying to create a program that will read a file that looks like this:
AAA x 111
AAB x 111
AAA x 112
AAC x 123
...
the file is 50 lines long and I'm trying to make the letters into keys in a dictionary and the numbers lists that correspond with the keys.
I want the output to look like this:
{AAA: ['111', '112'], AAB: ['111'], AAC: [123], ...}
This is what I've tried
file = open("filename.txt", "r")
readline = file.readline().rstrip()
while readline!= "":
list = []
list = readline.split(" ")
j = list.index("x")
k = list[0:j]
v = list[p + 1:]
d = {}
if k in d == False
d[k] = []
d[k].append(v)
else
d[k].append(v)
readline = file.readline().rstrip()
I keep getting syntax errors on my if statement and I can't figure out what I've done wrong.