sentence = 'ASK NOT WHAT YOUR COUNTRY CAN DO FOR YOU ASK WHAT YOU CAN DO FOR YOUR COUNTRY'
words = sentence.split()
# Counting backwards through the words means the last seen one will have
# the lowest index without needing 'if' tests or incrementing counters.
positions = {word:index for index, word in reversed(list(enumerate(words, 1)))}
print(' '.join(str(positions.get(word)) for word in words))
Try it on repl.it here: https://repl.it/CHvy/0