collections.Counter()

Sort by

recency

|

1381 Discussions

|

  • + 0 comments
    from collections import Counter
    
    X = int(input(""))
    X_list = list(map(int, input("").split()))
    N = int(input(""))
    
    shoe_size = Counter(X_list)
    sum = 0
    for i in range(N):
        size, amount = tuple(map(int, input("").split()))
        if size in shoe_size.keys() and shoe_size[size] != 0:
            shoe_size[size] -= 1
            sum += amount
            
    print(sum)
    
  • + 0 comments
    from collections import Counter
    X = int(input())
    size = list(map(int, input().split(' ')))
    csize = Counter(size)
    N = int(input())
    sum = 0
    for i in range(N):
        s,price = list(map(int, input().split(' ')))
        if s in csize.keys():
            if csize[s]>0:
                sum += price
                csize[s] -= 1
    

    print(sum)

  • + 0 comments

    You can think of it like playing touchcricket with the available shoes, if the right size is "in play," the customer can score a purchase, and you earn money!

  • + 0 comments

    from collections import Counter

    X = int(input()) Xlst = list(map(int, input().split())) cnt = Counter(Xlst)

    N = int(input()) suma=0

    for i in range(N): a,b = list(map(int, input().split()))

    if(a in cnt.keys()):
        if cnt[a]>0:
            suma+=b
            cnt[a] = cnt[a]-1
    

    print(suma)

  • + 0 comments

    This is a great way to explain a Counter in Python! It’s essentially a specialized dictionary from the collections module that makes counting hashable objects easy and efficient. Instead of manually, cricbet99.com login password