We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Python
- Collections
- Word Order
- Discussions
Word Order
Word Order
Sort by
recency
|
1555 Discussions
|
Please Login in order to post a comment
a = int(input()) result = dict() temp_result = [] for i in range(a): word = input() if word in result: result[word] += 1 else: result[word] = 1
total_keys = 0
for key, values in result.items(): total_keys += 1 temp_result.append(values)
print(total_keys) for res in temp_result: print(res, end= ' ')
using counter
from collections import Counter n=int(input()) # no of words 4 ls=[] for i in range(n): w=input() ls.append(w)
ls=Counter(ls) print(len(ls.keys())) for i in ls.values(): print(i,end=' ')
n = int(input()) dic = {}
for _ in range(n): word = input() if word not in dic.keys(): dic[word] = 1 elif word in dic.keys(): dic[word] = 1+dic[word]
print(len(dic)) quan = list(dic.values())
quan.sort(reverse=True)
print(" ".join(map(str,quan)))