歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux綜合 >> Linux資訊 >> 更多Linux

用Python實現文件亂序

  # 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 --- !




Copyright © Linux教程網 All Rights Reserved