# randomize the lines in a file # input file is list.txt, output file is listu.txt # Matt Bishop, March 1, 2012 # ECS 10, Winter 2012 import random # # open the file and read in the lines # f = open("list.txt", "r") flines = f.readlines() num = len(flines) # #randomize the order of the lines # doing it num times is probably overkill! # for i in range(num): line1 = random.randrange(num) line2 = random.randrange(num) flines[line1], flines[line2] = flines[line2], flines[line1] # # now write out the lines # g = open("listu.txt", "w") g.writelines(flines) # # clean up and quit # f.close() g.close()