JavaScript
x
2
1
import pickle`f=open('/home/nikan/Desktop/Linux os/text/word.txt', 'rb')
2
pickle.load(f)`
Advertisement
Answer
The problem was that only a single word was inputted and the sort method has been invoked on it.
Let’s get multiple words, append them to a list and sort them:
JavaScript
1
22
22
1
input_words = []
2
3
# Get input words
4
word = input('Please enter wordn')
5
# As long as word is not "stop"
6
while word != 'stop':
7
# Get new input word
8
input_words.append(word)
9
# Append to list of words
10
word = input('Please enter wordn')
11
12
# Sort words
13
input_words.sort()
14
15
# Print sorted list of words
16
print(input_words)
17
18
# Write to file
19
with open('your_file.txt', 'w') as f:
20
for item in input_words:
21
f.write("%sn" % item)
22