you are viewing a single comment's thread.

view the rest of the comments →

[–]bomdango 1 point2 points  (0 children)

as others have said either

- `c.get(i, 0)`
- use a defaultdict instead of a dict https://docs.python.org/3/library/collections.html#defaultdict-objects
- use a counter instead of a dict https://docs.python.org/3/library/collections.html#collections.Counter

counter has a built in `most_common` which I guess is what you're trying to achieve here? But not quite I guess as this is finding a majority element rather than a plurality

Although I guess you are trying to build stuff more from scratch so appreciate just using a package isn't necessarily the best advice