Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- from collections import Counter
- # Opening JSON file with 'r' flag:
- with open("birthdays.json", "r") as f:
- birthdays = json.load(f)
- # create first list to pull out values and store them as list items:
- bdayList = (entry['birthday'] for entry in birthdays['people'])
- # create bdayList2 to extract dates and store them in a separate list
- bdayList2 = (date.split(" ")[0] for date in bdayList)
- # use Counter module as variable 'c':
- c = Counter(bdayList2)
- # creating a tuple of all months to loop through later:
- months = ('January', 'February', 'March', 'April', 'May', 'June',
- 'July', 'August', 'September', 'October', 'November', 'December')
- # for loop to print the number of birthdays available in order:
- for month in months:
- print("{} = {}".format(month, c[month]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement