Advertisement
Guest User

nesteddictionariesautomatetheboringstuff

a guest
Nov 28th, 2015
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. allGuests = {'Alice': {'apples':5, 'pretzels':12},
  2. 'Bob': {'ham sandwiches': 3, 'apples': 2},
  3. 'Carol': {'cups': 3, 'apple pies': 1}}
  4.  
  5. def totalBrough(guests, item):
  6. numbBrought = 0
  7. for k, v in guests.items():
  8. numBrought = numBrought + v.get(item,0)
  9. return numBrought
  10.  
  11. print('Number of things being brought:')
  12. print(' - Apples '+ str(totalBrought(allGuests 'apples')))
  13. print(' - Cups '+ str(totalBrought(allGuests 'cups')))
  14. print(' - Cakes '+ str(totalBrought(allGuests 'cakes')))
  15. print(' - Ham Sandwiches '+ str(totalBrought(allGuests 'ham sandwiches')))
  16. print(' - Apple Pies '+ str(totalBrought(allGuests 'apple pies')))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement