Sort by

recency

|

1638 Discussions

|

  • + 0 comments

    from collections import Counter n=int(input()) word=[] for _ in range(n): word.append(input()) a=list(Counter(word).values()) print(len(a)) for i in a: print(i, end=' ')

  • + 0 comments
    # Enter your code here. Read input from STDIN. Print output to STDOUT
    from collections import Counter
    words = [input().strip() for _ in range(int(input()))]
    count = Counter(words)
    print (len(count))
    print (" ".join(map(str,count.values())))``
    
  • + 0 comments
    from collections import Counter
    
    n = int(input())
    words = [input() for _ in range(n)]
    counts = Counter(words)
    
    print(len(counts))
    for count in counts.values():
        print(count, end=" ")
    
  • + 0 comments

    no modules required

    n=int(input()) d={} for i in range(n): w=input() if w in d.keys(): d[w]+=1 else: d[w]=1 print(len(d)) for i in d.keys(): print(d[i],end=' ') print()

  • + 0 comments

    With Counter in Collection Module:

    from collections import Counter
    
    n= int(input())
    inp= [input() for _ in range(n)]
    counter_word = Counter(inp)
    
    key = len([key for key in counter_word.keys()])
    value = " " .join([str(value) for value in counter_word.values()])
    print(key)
    print(value)
    

    Without Counter in Collection module (Conventional Approach):

    n= int(input())
    inp= [input() for _ in range(n)]
    
    inp_unique= []
    count_all = []
    
    for i in inp:
        count= 1
        if i not in inp_unique:
            inp_unique.append(i)
            count_all.append(count)           
        else:
            inp_unique.index(i)
            count_all[inp_unique.index(i)] = count_all[inp_unique.index(i)] + 1
    
    print(len(inp_unique))
    print(" ".join((map(str, count_all))))