Sorting a Counter by key: Ordering a text histogram with sorted

Sorting a Counter by key: Ordering a text histogram with sorted

Let’s sort yesterday’s Python histogram by date! Counter is a dict, and the keys are ints, so sorted will do what we want:

for date, count in sorted(Counter([one_tg.day
    for one_tg in us_holidays.get_named('Thanksgiving')]).items()):
        print(f'{date}: {count * 'x'}')