ITPub博客

首页 > 应用开发 > IT综合 > 用Python实现文件乱序(转)

用Python实现文件乱序(转)

原创 IT综合 作者:post0 时间:2007-08-10 12:37:36 0 删除 编辑
用Python实现文件乱序(转)[@more@]

# cat test.dat

1 --- I

2 --- L

3 --- O

4 --- V

5 --- E

6 --- Y

7 --- O

8 --- U

9 --- !

10 --- !

# cat r.py

import sys,random

lines = sys.stdin.readlines()

olines=[]

while lines:

olines.append(lines.pop(random.randrange(len(lines))))

sys.stdout.write( "".join(olines))

# cat test.dat | python r.py

6 --- Y

4 --- V

8 --- U

5 --- E

3 --- O

2 --- L

1 --- I

10 --- !

7 --- O

9 ---

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/8225414/viewspace-940634/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: NAT使用实例(转)
请登录后发表评论 登录
全部评论
  • 博文量
    2018
  • 访问量
    8225237