About the challenge Counter All discussions about it
Solved

Counter vs dict with get()

ZosiaNOP

Is Counter just a dict?

2

Comments 4

Join the discussion

Already have an account? Log in

  1. CharlieH Solutionreplies: 2

    It's a dict subclass where missing keys return 0 instead of raising KeyError. So counts[level] += 1 just works. Plus extras like most_common() and adding/subtracting counters.

    8
    1. ZosiaNOPreplies: 1

      So it's dict + sensible defaults + helpers.

      0
    2. TomBecker

      Counter(levels_list) counts a whole list in one go, no loop needed.

      4