#!/usr/bin/env python3 """ Convert a list with duplicate lines into a list of sorted unique lines. The output lines will be sorted by their frequency in the input, ordered from most frequent to least frequent. """ import sys counts = { } for line in sys.stdin: line = line.strip() counts[line] = counts.get(line, 0) + 1 for key, ignored_val in sorted(counts.items(), key=lambda pair: pair[1], reverse=True): print("%s" % key)