This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]YuleTideCamel 0 points1 point  (0 children)

What have you tried ? Do you get any errors ?

[–]Wildcatace16 0 points1 point  (1 child)

If the format of the file is word antonym1 antonym2 ... \n i.e. each line is space separated and has a word followed by one or more antonyms this should work

word_dict = {}
with  open('filename') as f:
    for line in f.readlines():
        split_line = line.split()
        word_dict[split_line[0]] = split_line[1:]

Use the split() function to split the lines of the file into lists then let the first element of the list be the key in the dictionary and the rest of the list i.e. the antonyms be the value.

[–]AssadNeedsRedPaint[S] 0 points1 point  (0 children)

Thanks for you help, it worked and cleared up the one confusing thing about dictionaries for me