歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> Linux資訊 >> 更多Linux >> 亂序排列文件中的所有行

亂序排列文件中的所有行

日期:2017/2/27 9:22:39   编辑:更多Linux
  [root@www root]# more test.dat 1 --- I 2 --- L 3 --- O 4 --- V 5 --- E 6 --- Y 7 --- O 8 --- U 9 --- ! 10 --- ! [root@www root]# more 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)) [root@www root]# cat test.dat python r.py 5 --- E 3 --- O 6 --- Y 10 --- ! 8 --- U 1 --- I 7 --- O 2 --- L 9 --- ! 4 --- V




Copyright © Linux教程網 All Rights Reserved