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.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Python
  3. Collections
  4. Word Order
  5. Discussions

Word Order

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 1471 Discussions, By:

recency

Please Login in order to post a comment

  • agentkaumal88
    2 days ago+ 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|
    Permalink
  • ashley_yue117
    1 week ago+ 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|
    Permalink
  • divyagitika
    1 week ago+ 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|
    Permalink
  • akashjoy2023
    2 weeks ago+ 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|
    Permalink
  • anw_g01
    2 weeks ago+ 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())))
    
    0|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy