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 :)

Recommended Answers

All 7 Replies

I don't understand what you are asking for. Could you explain, maybe give a short example?

ok so basically i have a file that i read and count using dictionary the occurance of particular triples from a line.
onece ive counted the combination and the number of combinatin i want to then print the lines to a file ?
so my first triple is,
4, 22, 51): 3
so i want to randomly selct 2 line with this triple present init then do the same for the next
4, 22, 33): 2

so it will print lines as follows
4 22 7 51..........
4 22 5 33 .......

Sorry, me too I don't understand.

Philippe

Member Avatar for sravan953

I kinda understand your problem.

You want to print the lines(and their 'line number') containing a specific triple to another file?

I don't understand how you go from :
(4, 22, 51): 3
to:
4 22 7 51

hi sorry well my (4, 22, 51): 3
is a print out of mu dictionary key and values
and the 4 22 7 51 ...... is the line which has my tuple that is my dictionary keybasically i read every line in my file and count them according to numbers at position[0],[1] and [3]

Please don't double post. Stick with one thread and mark the other "Closed" or "Solved". And a title like "someone please help!!!!!!!!!!" will get less responses not more. It does not state a specific problem and indicates someone who is looking for someone to write free programs for them. The few who donate some time answering questions would soon be overwhelmed if we allowed that to happen.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.