Sort by

recency

|

1645 Discussions

|

  • + 0 comments
    from collections import Counter
    words = [input() for _ in range(int(input()))]
    print(len(Counter(words)))
    counts = [i  for i in Counter(words).values()]
    print(' '.join([str(i) for i in counts]))
    
  • + 0 comments
    from collections import Counter
    
    def main():
        n = int(input())
        words = [input() for _ in range(n)]
        counter = Counter(words)
        counts = [str(w) for w in list(counter.values())]
        print(len(counter))
        print(' '.join(counts))
    
    if __name__ == "__main__":
        main()
    
  • + 1 comment
    # Enter your code here. Read input from STDIN. Print output to STDOUT
    from collections import OrderedDict
    n = int(input())
    
    ordered_dict = OrderedDict()
    for i in range(n):
        line = input()
        if line in ordered_dict:
            ordered_dict[line] = ordered_dict[line]+1
        else:
            ordered_dict[line] = 1
            
    print(len(ordered_dict))
    
    
    result =   " ".join(str(ordered_dict[key]) for key in ordered_dict)
    print(result)
        
        
    
  • + 0 comments

    What about this:

    if __name__ == "__main__":
        n = int(input().strip())
        words = [input().strip() for _ in range(n)]
        counters = {}
        
        for word in words:
            counters[word] = counters.get(word,0)+1        
    
        print(len(counters))
        print(" ".join(map(str, counters.values()))
    
  • + 0 comments
    total_words=int(input())
    words= [str(input()) for string in range(total_words)]
    
    # Solution 1
    output=dict()
    for word in words:
        if word not in output:
            output[word]=1
        else:
            output[word]+=1
    print(len(output.keys()))
    print(*output.values(),sep=" ")