Sort by

recency

|

1660 Discussions

|

  • + 0 comments
    from collections import defaultdict
    
    num_words = int(input())
    
    word_frequency: defaultdict[str, int] = defaultdict(int)
    
    for _ in range(num_words):
        word = input().strip()
        word_frequency[word] += 1
    
    print(len(word_frequency))
    
    for word in word_frequency:
        print(word_frequency[word], end=" ")
    
  • + 0 comments
    from collections import defaultdict
    
    num_words = int(input())
    
    word_frequency: defaultdict[str, int] = defaultdict(int)
    
    for _ in range(num_words):
        word = input().strip()
        word_frequency[word] += 1
    
    print(len(word_frequency))
    
    for word in word_frequency:
        print(word_frequency[word], end=" ")
    
  • + 0 comments
    from collections import OrderedDict
    
    input_dict = OrderedDict()
    
    for _ in range(int(input())):
        word = input()
        try:
            input_dict[word] += 1
        except KeyError:
            input_dict[word] = 1
    
    print(len(input_dict))
    for val in input_dict.values():
        print(val, end = " ")
    
  • + 0 comments
    n = int(input())
    words = {}
    
    for _ in range(n):
        word = str(input())
        if word not in words:
            words[word] = 1
        else:
            words[word] += 1
    
    word_list = [str(i) for i in list(words.values())]
            
    print(len(words.keys()))
    print(' '.join(word_list))
    
  • + 0 comments

    `n=int(input()) l=[input() for i in range(n)] freq={} order=[] for i in l: if i not in freq: freq[i]=1 order.append(i) else: freq[i]+=1 print(len(order)) for i in order: print(freq[i],end=' ')

    `