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))
            Asked
            
        
        
            Active
            
        
            Viewed 41 times
        
    -1
            
            
         
    
    
        Bhargav Rao
        
- 50,140
- 28
- 121
- 140
2 Answers
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
- 
                    I'm looking for an answer to my question though, is there any chance you could help. – Abby Wheeler Nov 16 '16 at 12:31
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
- 
                    I have already tried this but I don't know how to word it in with my code. – Abby Wheeler Nov 16 '16 at 12:18
- 
                    maybe like 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)) – Jesse Nov 16 '16 at 12:33
- 
                    
- 
                    
 
     
    