Kodewick
Start learning →
Basic←→0 / 80

Birthday months

#075BasicStringsDicts4 min

The class wrote birthdays as "month-day", like "03-21". Write by_month(birthdays) to count how many birthdays fall in each month, returning {month: count} with the month as a number (3, not "03").

Examples
by_month(["03-21", "11-02", "03-05"])→{3: 2, 11: 1}
by_month([])→{}
main.py
def by_month(birthdays):
    counts = {}
    for day in birthdays:
        # your code here: take the month out of day as a number (instead of month = 0)
        month = 0
        counts[month] = counts.get(month, 0) + 1
    return counts
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.