Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. import json
  2. from collections import Counter
  3.  
  4. # Opening JSON file with 'r' flag:
  5. with open("birthdays.json", "r") as f:
  6. birthdays = json.load(f)
  7.  
  8. # create first list to pull out values and store them as list items:
  9. bdayList = (entry['birthday'] for entry in birthdays['people'])
  10.  
  11. # create bdayList2 to extract dates and store them in a separate list
  12. bdayList2 = (date.split(" ")[0] for date in bdayList)
  13.  
  14. # use Counter module as variable 'c':
  15. c = Counter(bdayList2)
  16.  
  17. # creating a tuple of all months to loop through later:
  18. months = ('January', 'February', 'March', 'April', 'May', 'June',
  19. 'July', 'August', 'September', 'October', 'November', 'December')
  20.  
  21. # for loop to print the number of birthdays available in order:
  22. for month in months:
  23. print("{} = {}".format(month, c[month]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement