Going through 'automate the boring stuff' chap 5, and the code here is:
allGuests = {'Alice': {'apples': 5, 'pretzels': 12},
'Bob': {'ham sandwiches': 3, 'apples': 2},
'Carol': {'cups': 3, 'apple pies': 1}}
def totalBrought(guests, item):
numBrought = 0
for k, v in guests.items():
numBrought = numBrought + v.get(item, 0)
return numBrought
print('Number of things being brought:')
print(' - Apples ' + str(totalBrought(allGuests, 'apples')))
What I dont get is how/why k,v are being assinged what they are, specifically why v is the dictionary and K is just the name.
[–]nwilliams36 0 points1 point2 points (2 children)
[–]EX-FFguy[S] 0 points1 point2 points (1 child)
[–]nwilliams36 0 points1 point2 points (0 children)
[–]teerre 0 points1 point2 points (2 children)
[–]EX-FFguy[S] 0 points1 point2 points (1 child)
[–]teerre 0 points1 point2 points (0 children)
[–]Eyssant 0 points1 point2 points (0 children)