On Wed, 15 Jan 2020 at 13:37, Hunter Jones <hjones82...@gmail.com> wrote:
>
> Hey everyone,
>
> I recently used list.count() in a coding interview and the question arose 
> about how scale-able this solution was for sufficiently large input. 
> Currently, list.count iterates through the list, incrementing the count as it 
> goes and returning the value at the end. This does not lend itself well to 
> large inputs.
>
> I propose either modifying the list struct to include a map of item -> count, 
> or implementing a new structure with this information that is allocated 
> separately when a list is instantiated.
>
> Maybe I'm just seeing this since it's an edge case that I recently dealt 
> with, but I believe it would be a useful enhancement overall.

Personally, I don't think it's something that's needed often enough to
justify the overhead on such a core Python data structure. If you have
an application (or interview question!) that needs to maintain counts
a lot, then I'd suggest that you might want to use a different data
structure - maybe a collections.Counter, or implement your own "list
plus count mapping" data structure the way you suggest. But without
strong evidence that this would be used a lot, I don't think such a
feature justifies the cost as part of the built in list data
structure.

Paul
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/P4MQZXEIQT74MZMEK7GHE2XBYY3ZL745/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to