到目前为止我已经拿到了这个
UserSen = input("Enter a sentence of your choice, ")
position = {} # word -> position
words = UserSen.split()
for word in words:
if word not in position: # new word
position[word] = len(position) + 1 # store its position
我想把它写出来,比如说,如果你在句子“你好你好你好你好吗”,它会输出1,2,3,4,1,3,4,1
非常简单,您需要在目前找到的位置内保存一个列表:
相关问题 更多 >
编程相关推荐