You are viewing a single comment's thread. Return to all comments →
Before Python 3.7, the order is not guaranteed in dictionaries:
from collections import Counter, OrderedDict class OrderedCounter(Counter, OrderedDict): pass words = OrderedCounter(input() for _ in range(int(input()))) print(len(words)) print(*words.values())
Since Python 3.7, the order is guaranteed to be kept in dictionaries which makes the code even simpler:
from collections import Counter words = Counter(input() for _ in range(int(input()))) print(len(words)) print(*words.values())
Seems like cookies are disabled on this browser, please enable them to open this website
Word Order
You are viewing a single comment's thread. Return to all comments →
Before Python 3.7, the order is not guaranteed in dictionaries:
Since Python 3.7, the order is guaranteed to be kept in dictionaries which makes the code even simpler: