我有这个做我想做的事情(拿一个文件,打乱单词的中间字母并重新加入它们),但由于某种原因,即使我要求它在空格上拆分,空格也会被删除。这是为什么?
import random
File_input= str(input("Enter file name here:"))
text_file=None
try:
text_file = open(File_input)
except FileNotFoundError:
print ("Please check file name.")
if text_file:
for line in text_file:
for word in line.split(' '):
words=list (word)
Internal = words[1:-1]
random.shuffle(Internal)
words[1:-1]=Internal
Shuffled=' '.join(words)
print (Shuffled, end='')