I have a Wordnet text entry that i am trying to assign variables to. I have assigned any variable that only occurs once but in some text lines there might be multiple words. this leads to a problem as i dont know how to assign them so that the number of words in the text equals the number of variables assigned to word1, word2 etc.
here is a sample of the line I am reading
09824747 18 n 02 archer 0 bowman 0 003 @ 09640897 n 0000 ~ 10290474 n 0000 ~i 10718145 n 0000 | a person who is expert in the use of a bow and arrow
In this case I would like to call word1=archer and word2 = bowman.
I can use this
f = open("wordnetSample.txt", "r")
for line in f:
L = line.split()
word = [L[4:4 + 2 * int(L[3]):2]]
but it will only put the words in a list, not assigning them variable names I can use further on.
I would also like to know how i go about inserting them into my later code, that may look something list this:
print('the words in this synset are '+word(i)+','+word(i+1)+','+word(i+n)+')
I don't exactly understand what you're trying to do, but the expression you have above will store the words in a list, it is not a dictionary. You could actually:
print('the words in this synset are ' + word[0] + ',' + word[1])
Note that you need to use [] and not () as you write above. More elegant would be the following:
print ("the words in this synset are {0}".format(", ".join(word)))
because that works with an unknown number of words.