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
+ 0 comments N = int(input()) d = {} for _ in range(N): w = input() if w in d: d[w] += 1 else: d[w] = 1 print(len(d)) print(*d.values())
+ 0 comments from collections import OrderedDict od = OrderedDict() for _ in range(int(input())): word = input() if word in od: od[word] += 1 else: od[word] = 1 print(len(od)) print(*od.values())
+ 0 comments from collections import defaultdict n=int(input()) d=defaultdict(list) for i in range(n): s=input() d[s].append(i) print(len(d.keys())) print(*list(map(lambda x:len(x),d.values())))
+ 0 comments from collections import OrderedDict if __name__ == '__main__': ord_dict = OrderedDict() n = int(input()) #inp = list() for i in range(n): inp = input() if inp in ord_dict: ord_dict.update({inp:ord_dict.get(inp)+1}) else: ord_dict.update({inp:1}) print(len(ord_dict)) print(*ord_dict.values())
+ 0 comments n = int(input()) unique_words = set() word_count = {} for _ in range(n): word = input() unique_words.add(word) word_count[word] = word_count.get(word, 0) + 1 print(len(unique_words)) print(" ".join(map(str, word_count.values())))
Load more conversations
Sort 1471 Discussions, By:
Please Login in order to post a comment