python 3.x - My program isn't sorting properly -
im making histogram file , got working not sorting them correctly. meaning 100 90 50 etc.
here code:
from collections import counter data=[] open("data.txt", 'r') f: line in f: line = line.strip() data.append(str(line)) counts = counter(data) key, size in sorted(counts.items()): print('{}: {}'.format(key, int(size) * '*'))
this output:
100: ****** 25: ** 50: *** 60: * 65: * 70: ** 75: * 80: **** 85: **** 90: ***
any suggestions??
edit:
what mean go numerically in order. insted of 100, 25, 50, .... want 100, 90, 85,.....
njzk2 absolutely right, thanks! 1 way can :
... line = line.strip() # casting 'int' type before populating in data table.. data.append(int(line)) ...
then, can
... # applying reversed reorder ascending order descending order. key, size in sorted(counts.items(), reverse=true): ...
Comments
Post a Comment