Files
courses/py3interm/mylabs/pres_by_state_sorted.py
2025-05-20 11:57:43 -04:00

16 lines
391 B
Python

#!/usr/bin/python
with open("../DATA/presidents.txt") as pres_in:
count_of = {}
for rec in pres_in:
flds = rec.split(":")
state = flds[6]
if state in count_of:
count_of[state] += 1
else:
count_of[state] = 1
for state, count in sorted(count_of.items(), key=lambda e: (-e[1], e[0])):
print(("%-16s %2d" % (state, count)))