Aoccdrnig to a rscheearch at Cmabrigde Uinervtisy, it deosn't mttaer in waht oredr the ltteers in a wrod are, the olny iprmoetnt tihng is taht the frist and lsat ltteer be at the rghit pclae. The rset can be a total mses and you can sitll raed it wouthit porbelm. Tihs is bcuseae the huamn mnid deos not raed ervey lteter by istlef, but the wrod as a wlohe. Amzanig!
根据此原理.我实现了一个英文脑残体生成器.
原文:
D:/Desk/Python>more rand_test.txt
There is nothing to download or install.
Create online survey with our intuitive survey editor with dozen
types of questions simple with an internet explorer
脑残以后
D:/Desk/Python>more rand_test.txt|python random_letter_order.py -
Tehre is nntohig to dlowanod or isntlal.
Crteae onnlie survey wtih our ittiinuve svurey edoitr wtih dozen
tepys of quetosins sipmle wtih an internet erxploer
代码.需要python环境
__author__="leo"
import random
import sys
def rand_word(word):
if len(word)==4:
return word[0]+word[2]+word[1]+word[3]
temp=[]
temp.append(word[0])
for i in word[1:-1]:
temp.insert(random.randint(1,len(word)),i)
temp.append(word[-1])
return ''.join(temp)
def rand_line(s):
new_words=[]
words=s.split()
for word in words:
if len(word)>3:
new_word=rand_word(word)
new_words.append(new_word)
else:
new_words.append(word)
print " ".join(new_words)
if len(sys.argv) == 1:
print """Usage:
In windows sytem:
more file|python random_letter_order.py -
In linux or unix system:
cat file|python random_letter_order.py - """
exit()
for lines in sys.stdin:
rand_line(lines)