Sort by

recency

|

1642 Discussions

|

  • + 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=" ")
    
  • + 0 comments
    #without any  modules
    
    n = int(input())
    words = [input() for i in range(n)]
    
    result = {}
    
    for word in words:
        if word not in result:
            result[word] = 1
        elif word in result:
            result[word] += 1
            
    print(len(result))
    for i in result.values():
        print(i, end = ' ')
    
  • + 0 comments

    without any modules

    n = int(input()) words = [input() for i in range(n)]

    result = {}

    for word in words: if word not in result: result[word] = 1 elif word in result: result[word] += 1

    print(len(result)) for i in result.values(): print(i, end = ' ')

    print(len(result)) for i in result.values(): print(i, end = ' ')

  • + 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=' ')