collections.Counter()

Sort by

recency

|

1400 Discussions

|

  • + 0 comments
    from collections import Counter
    # Enter your code here. Read input from STDIN. Print output to STDOUT
    x = int(input())
    sizes = map(int, input().split())
    n = int(input())
    avail = Counter(sizes)
    sales = 0
    for i in range(n):
        order = list(map(int, input().split()))
        size = order[0]
        if size in avail.keys() and avail[size] > 0:
            sales += order[1]
            avail[size] -= 1
    
    print(sales)
    
  • + 0 comments

    from collections import Counter list1 = [] def test(customer_shoe_size,price): if customer_shoe_size in shoe_sizes.keys(): value = shoe_sizes.get(customer_shoe_size) shoe_sizes.subtract([customer_shoe_size]) if value > 0: list1.append(int(price))

    def sum_(): final = list(map(int,list1)) print(sum(final))

    if name == "main": global shoe_sizes no_of_shoes = int(input()) shoe_sizes = Counter((map(str,input().split()))) no_of_customers = int(input()) for i in range(no_of_customers): customer_shoe_size , price = input().split() test(customer_shoe_size,price) sum_()

  • + 0 comments

    X = int(input()) tot_inv = list(map(int, input().split()))

    from collections import Counter

    inventory = Counter(tot_inv)

    N = int(input())

    raghu_earn = 0

    for _ in range(N):

    size_price = input().split()
    size = int(size_price[0])
    price = int(size_price[1])
    
        if inventory[size]>0:
        raghu_earn+=price
        inventory[size]-=1
    

    print(raghu_earn)

    if inventory[size]>0:
        raghu_earn+=price
        inventory[size]-=1
    

    print(raghu_earn)

  • + 0 comments

    from collections import Counter

    def calc_earnings(shoes, customers):

    earnings = 0
    
    for c in customers:
        if c[0] not in shoes: continue
    
        shoes[c[0]] -= 1
        earnings += c[1]
    
        if (shoes[c[0]] <= 0): del shoes[c[0]]
    
    print(earnings)
    

    if name=='main':

    input() # We really don't use this info (number of shoes).
    shoes = Counter(map(int, input().split()))
    n = int(input())
    
    customers = []
    
    for _ in range(n):
        shoe_size, price = map(int, input().split())
        customers.append((shoe_size, price))
    
    calc_earnings(shoes, customers)
    
  • + 0 comments

    Here is HackerRank collection.counter() in python solution - https://programmingoneonone.com/hackerrank-collections-counter-solution-in-python.html