Kodewick
Start learning →
Basic←→0 / 80

Dice tally

#034BasicDictsLoops4 min

During a board game you wrote down every dice roll. Write dice_counts(rolls) to return a dict {face: times rolled}, in the order each face first appeared. No rolls gives {}.

Examples
dice_counts([3, 6, 3, 1])→{3: 2, 6: 1, 1: 1}
dice_counts([])→{}
main.py
def dice_counts(rolls):
    counts = {}
    # your code here: loop over rolls and add 1 to that face's count (starting from 0 the first time)
    return counts
Ctrl + Enter runs too
Result

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