脑残体自动生成器

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)

    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值