Hellow help me please

for keyword in keyword_sentence_mapping:

wordsense = get_wordsense(keyword_sentence_mapping[keyword][0],keyword)

if wordsense:

    distractors = get_distractors_wordnet(wordsense,keyword)

    if len(distractors) ==0:

        distractors = get_distractors_conceptnet(keyword)

    if len(distractors) != 0:

        key_distractor_list[keyword] = distractors



    distractors = get_distractors_conceptnet(keyword)

    if len(distractors) != 0:

        key_distractor_list[keyword] = distractors

index = 1

for each in key_distractor_list:

sentence = keyword_sentence_mapping[each][0]

pattern = re.compile(each, re.IGNORECASE)

output = pattern.sub( " _______ ", sentence)

print ("%s)"%(index),output)

choices = [each.capitalize()] + key_distractor_list[each]

top4choices = choices[:4]


optionchoices = ['a','b','c','d']

for idx,choice in enumerate(top4choices):

    print ("\t",optionchoices[idx],")"," ",choice)

print ("\nMore options: ", choices[4:20],"\n\n")

index = index + 1

###but when I run this project there is an error bellow
IndexError Traceback (most recent call last)

in ()
72 for keyword in keyword_sentence_mapping:
—> 73 wordsense = get_wordsense(keyword_sentence_mapping[keyword][0],keyword)
74 if wordsense:
75 distractors = get_distractors_wordnet(wordsense,keyword)

IndexError: list index out of range

1 Like

This post was flagged by the community and is temporarily hidden.

1 Like

The only list index access in that line is keyword_sentence_mapping[keyword][0], so the error implies that keyword_sentence_mapping[keyword] is an empty list (so there is no element 0 to read).

There’s not enough context to guess why that might be, if you need more help it’d be good to describe what you’re trying to do.

1 Like

I needed to run the program of generating multiple choice question through google collaboration thats why i met with this error