ok so my code is as follows:
read=open('mon_17.py','r')
reader=read.readlines()
a=[]
for line in reader:
reader1=[]
for i, entry in enumerate(line.split()):
if i in range(0,4)+[6]:
reader1.append(int(entry))
else:
reader1.append(float(entry)) #float the 2 purity values only at this point
#reader1=map(float,line.split())#this was made everthing diff made all floats
a.append(reader1)
a.sort(lambda x,y:cmp(x,y))
read.close()
match={}
for values in a:
#print values
triple=(values[0], values[2], values[3])
if not match.has_key(triple):
match[triple] =0
match[triple]+=1 # this will start at 0 and then also count the triple
and i get an output as follows {(4, 22, 51): 3, (4, 22, 33): 2, (4, 22, 4): 3, (4, 22, 107): 1, (4, 22, 32): 4, (4, 22, 25): 5, (4, 22, 7): 4, (4, 22, 53): 3, (4, 22, 106): 1, (4, 22, 35): 3, (4, 22, 24): 1, (4, 22, 81): 1, (4, 22, 52): 2, (4, 22, 34): 2, (4, 22, 27): 2, (4, 22, 80): 1, (4, 22, 9): 1, (4, 22, 37): 3, (4, 22, 26): 4, (4, 22, 8): 4, (4, 22, 54): 1, (4, 22, 36): 3, (4, 22, 29): 2, (4, 22, 82): 1, (4, 22, 11): 2, (4, 22, 39): 2, (4, 22, 28): 3, (4, 22, 10): 2, (4, 22, 67): 1, (4, 22, 38): 4, (4, 22, 13): 2, (4, 22, 41): 5, (4, 22, 30): 2, (4, 22, 12): 3, (4, 22, 69): 2, (4, 22, 40): 6, (4, 22, 15): 2, (4, 22, 43): 3, (4, 22, 96): 2, (4, 22, 14): 6, (4, 22, 42): 4, (4, 22, 99): 1, (4, 22, 45): 2, (4, 22, 62): 1, (4, 22, 44): 1, (4, 22, 19): 3, (4, 22, 72): 1, (4, 22, 1): 4, (4, 22, 47): 5, (4, 22, 100): 1, (4, 22, 18): 1, (4, 22, 46): 1, (4, 22, 103): 1, (4, 22, 92): 2, (4, 22, 21): 3, (4, 22, 74): 1, (4, 22, 3): 5, (4, 22, 49): 3, (4, 22, 102): 1, (4, 22, 95): 1, (4, 22, 2): 4, (4, 22, 105): 1, (4, 22, 23): 5, (4, 22, 5): 4}
if i print the dictionary,
this is on a test file
now i want to from each key print at random the line that has the key init???
how can i do this???
i could write each line in every key to a new file but how can i do this? im really stuck and my file is too large to use something like excel for this mini step please can i get some help :)