Problem.txt file:
Class    Confidence     Xmin       Ymin     Xmax      Ymax
6        0.9917297      62         0        81        76
1        0.99119675     0          41       8         83
9        0.8642462      23         31       46        98
4        0.8287333      22         30       45        95
My expected output is:
1        0.99119675     0          41       8         83
4        0.8287333      22         30       45        95
9        0.8642462      23         31       46        98
6        0.9917297      62         0        81        76
My code is given bellow:
from collections import defaultdict
import os
for root, dirs, files in os.walk(r'F:\GGR\process'):  # this recurses into subdirectories as well
    for f in files:
        maxima = defaultdict(int)
        try:
            with open(os.path.join(root,f)) as ifh:
                for line in ifh:
                    key, value = line.rsplit(None, 1)
                    value = int(value)
                    if value > maxima[key]:
                        maxima[key] = value
            with open(os.path.join(root, f'{f}.out'), 'w') as ofh:
                for key in sorted(maxima):
                    ofh.write('{} {}\n'.format(key, maxima[key]))
        except ValueError:
            # if you have other files in your dir, you might get this error because they
            # do not conform to the structure of your "needed" files - skip those
            print(f, "Error converting value to int:", value)
After run this script, Output will show:
1 0.99119675  0  41  8   83
4 0.8287333  22  30  45  95
6 0.9917297  62  0   81   76
9 0.8642462  23  31  46  98
I can't understand what is the wrong in my code. Please fix this problem anf how can i get expected output for this program ?
 
    