In [10]:
import numpy as np
In [11]:
f = open ('supermarket.txt')
lines = f.readlines()
In [12]:
breakpoint = 20
t = set()
def AddElements(line):
elements = line.split(" ")
for element in elements:
t.add(element.strip())
def AllElementsinSet(line):
elements = line.split(" ")
for element in elements:
if not element.strip() in t:
return False
return True
In [5]:
np.random.shuffle(lines)
outputfile=[]
def WriteToFile():
output = open('supermarket.dat','w')
for l in outputfile:
output.write(l)
In [7]:
for line in lines:
#outputfile.append(line)
AddElements(line)
if len(t)>breakpoint:
break
In [ ]:
for line in lines:
outputfile.append(line)
In [40]:
WriteToFile()
In [9]:
Out[9]: