Skip to content

Instantly share code, notes, and snippets.

@Unitoi01
Created April 23, 2018 19:11
Show Gist options
  • Save Unitoi01/5aaa2c9e8dbf9c611cebd9eac9c3705d to your computer and use it in GitHub Desktop.
Save Unitoi01/5aaa2c9e8dbf9c611cebd9eac9c3705d to your computer and use it in GitHub Desktop.
Takes from text file and shuffles, then iterates
import random
import time
def shuffleRead():
first=True
count=0
f=open('output.txt', 'r+')
lines= f.readlines()
if(first==True):
first=False;
with open('test.txt','r+') as source:
data= [(random.random(),line)for line in source]
data.sort()
with open('output.txt', 'w') as target:
for _, line in data:
target.write(line)
if count == 3:
count=0
with open('test.txt','r+') as source:
data= [(random.random(),line)for line in source]
data.sort()
with open('output.txt', 'w') as target:
for _, line in data:
target.write(line)
f=open('output.txt','r+')
lines= f.readlines()
else:
print(lines[count])
count= count +1
time.sleep(1)
while True:
shuffleRead()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment