Created
April 23, 2018 19:11
-
-
Save Unitoi01/5aaa2c9e8dbf9c611cebd9eac9c3705d to your computer and use it in GitHub Desktop.
Takes from text file and shuffles, then iterates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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