婷婷同學(xué)_
2023-08-15 16:37:54
import pickle`f=open('/home/nikan/Desktop/Linux os/text/word.txt', 'rb')pickle.load(f)`
1 回答

千巷貓影
TA貢獻1829條經(jīng)驗 獲得超7個贊
問題是只輸入了一個單詞并且對其調(diào)用了排序方法。
讓我們獲取多個單詞,將它們附加到列表中并對它們進行排序:
input_words = []
# Get input words
word = input('Please enter word\n')
# As long as word is not "stop"
while word != 'stop':
# Get new input word
input_words.append(word)
# Append to list of words
word = input('Please enter word\n')
# Sort words
input_words.sort()
# Print sorted list of words
print(input_words)
# Write to file
with open('your_file.txt', 'w') as f:
for item in input_words:
f.write("%s\n" % item)
添加回答
舉報
0/150
提交
取消