Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def make_comparator(less_than):
- def compare(x, y):
- if less_than(x, y):
- return -1
- elif less_than(y, x):
- return 1
- else:
- return 0
- return compare
- def cmp_(x, y):
- return x[0] > y[0] or (x[0] == y[0] and x[1] < y[1])
- words_dict = dict()
- for i in range(int(input())):
- for word in input().split():
- words_dict[word] = words_dict.get(word, 0) + 1
- print([(v, k) for k, v in words_dict.items() ])
- print(sorted([(v, k) for k, v in words_dict.items() ], cmp = make_comparator(cmp_)))
- """
- 2
- asd asd
- qwe q
- [(2, 'asd'), (1, 'qwe'), (1, 'q')]
- Traceback (most recent call last):
- File "c:/Users/Asus/AppData/Local/Programs/Python/Python36/456.py", line 23, in <module>
- print(sorted([(v, k) for k, v in words_dict.items() ], cmp = make_comparator(cmp_)))
- TypeError: 'cmp' is an invalid keyword argument for this function
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement