In [16]:
import numpy as np
In [17]:
f = open ('supermarket.txt')
lines = f.readlines()
In [18]:
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 [19]:
np.random.shuffle(lines)
outputfile=[]
def WriteToFile():
output = open('supermarket.dat','w')
for l in outputfile:
output.write(l)
In [20]:
for line in lines:
#outputfile.append(line)
AddElements(line)
if len(t)>breakpoint:
break
In [22]:
for line in lines:
if AllElementsinSet(line):
outputfile.append(line)
In [40]:
WriteToFile()
In [24]:
len(outputfile)
Out[24]: