-1
sentence = input('Please enter your sentence: ')
words = sentence.split()

positions = {word:index for index, word in reversed(list(enumerate(words, 1)))}

print(' '.join(str(positions.get(word)) for word in words))
Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140

2 Answers2

0

The question is not general enough, I think it should be "How to write a file in python", also, you may want to read the docs before asking here.

https://docs.python.org/2/tutorial/inputoutput.html

with open('filename', 'w') as the_file:
    the_file.write(whatever)
Luis Sieira
  • 29,926
  • 3
  • 31
  • 53
0
f = open('out.txt', 'w')
f.write('...\n')
f.close()

this info came from How to redirect 'print' output to a file using python? ;)

f.open=('PathToFile', 'w')
sentence = input('Please enter your sentence: ')
    words = sentence.split()
    positions = {word:index for index, word in reversed(list(enumerate(words, 1)))}
    f.write(' '.join(str(positions.get(word)) for word in words))
f.close
Community
  • 1
  • 1
Jesse
  • 39
  • 8