Individual words in a list then printing the positions of those words

前端 未结 5 1369
逝去的感伤
逝去的感伤 2020-12-20 02:54

I need help with a program that identifies individual words in a sentence, stores these in a list and replaces each word in the original sentence with the position of that w

5条回答
  •  自闭症患者
    2020-12-20 03:37

    Instead of the OrderedDict you could just use a set.

    refined = list(set(FilteredSentence))
    

    than you can check each word against the list.

    index_list = []
    for word in FilteredSentence:
        index_list.append(refined.index(word) +1)
    

    index_list is the result you asked for

提交回复
热议问题