The Task is:
Raghu is a shoe shop owner. His shop has X number of shoes.
He has a list containing size of each shoe he has in his shop.
There are N number of customers, who are willing to pay xi amount of money only if they get the shoe of their desired size.
Your task is to compute, how much money Raghu earned.
Input Format
First line contains, X number of shoes.
Second line contains, space separated size of the shoes.
Third line contains, N number of customers.
Next N line contain, space separated values of shoe size and xi price of shoe.
The ACTUAL Input
10
2 3 4 5 6 8 7 6 5 18
6
6 55
6 45
6 55
4 40
18 60
10 50
X = int(input()) # Number of shoes
#10
#Spliting the input and changing it to an integer
N = map(int,input().split()) #Space separated list of shoe sizes in shop
#Outcome will be ["2","3","4","5","6","8","7","6","5","18"]
x = int(input()) # Number of customers
#6
L = map(tuple,(map(int,input().split()) for _ in range(x)))
# Take the shoe size and price of shoe for every customer for amount of customers
# and then convert to list of ints
# Then make them a Tuple
# Outcome will be (6, 55, 6, 45, 6, 55, 4, 40, 18, 60, 10, 50)
n = Counter(N)
# n {
# 2: 1,
# 3: 1,
# 4: 1, # -1 Subtracted in iteration
# 5: 2,
# 6: 2, # -1 Subtracted in iteration(twice)
# 8: 1,
# 7: 1,
# 18: 1, # -1 Subtracted in iteration
#}
p = 0 # counter to add/subtract to
for i in L:
if i[0] in n.keys() and n[i[0]] > 0 :
n[i[0]] = n[i[0]]-1
# Subtracts from key if item matches from L(is immutable tuple)
p = p+i[1] # + 55, + 45, + 40, + 60
#Since iterating through ALL L, one by one, Index i[1] would be next in list L
print(p)
Am I understanding this recursion correctly? The part I am having trouble understanding is how p is incrementing at index 1. Is this PURELY because of the line ***for i in L*** which makes it Iterate through the ENTIRE LIST starting the index over for each item?
I would love some clarification for my notes. <3
What I have tried:
Staring at the computer for 1 hour 45 minutes trying to break the recursion down, slowly adding notes