In [25]:
import numpy as np

In [26]:
f = open ('supermarket.txt')
lines = f.readlines()

In [27]:
breakpoint = 127
t = set()
def AddElements(line):
    elements = line.split(" ")
    for element in elements:
        t.add(element.strip())

In [28]:
np.random.shuffle(lines)
outputfile=[]
def WriteToFile():
    output = open('supermarket.dat','w')
    for l in outputfile:
        output.write(l)

In [29]:
for line in lines:
    outputfile.append(line)
    AddElements(line)
    if len(t)>breakpoint:
        break

In [30]:
r = 0 
for i in t:
    print r, i
    r+=1


0 15453
1 661
2 10349
3 4575
4 5509
5 6648
6 1834
7 6095
8 15361
9 5622
10 11668
11 543
12 2403
13 2923
14 2013
15 7752
16 1096
17 2916
18 14106
19 4336
20 12701
21 3330
22 4037
23 9985
24 13847
25 9171
26 12438
27 5308
28 3561
29 11375
30 7448
31 7728
32 6657
33 299
34 15598
35 827
36 7895
37 7893
38 9778
39 592
40 6606
41 5398
42 9091
43 6385
44 14456
45 11887
46 13599
47 5496
48 11567
49 7246
50 14754
51 6660
52 2384
53 6063
54 9788
55 1015
56 15589
57 13227
58 2265
59 6828
60 108
61 7864
62 11217
63 10543
64 13538
65 2835
66 5772
67 9579
68 8693
69 12845
70 11358
71 1643
72 10986
73 5086
74 1930
75 385
76 13973
77 9123
78 8078
79 14039
80 571
81 7008
82 5330
83 7340
84 9630
85 10795
86 11571
87 6042
88 15322
89 11748
90 12562
91 6688
92 3087
93 9132
94 5021
95 5023
96 11976
97 15547
98 11335
99 5896
100 6361
101 14
102 15315
103 1999
104 11148
105 10714
106 6193
107 9011
108 604
109 9343
110 9108
111 748
112 14977
113 12545
114 15377
115 12541
116 5641
117 14155
118 12469
119 48
120 1793
121 2508
122 12350
123 6973
124 3911
125 11679
126 4503
127 13478
128 13627
129 15011
130 1607
131 8950
132 7500

In [31]:
WriteToFile()