On 1/14/2020 11:03 PM, Hunter Jones wrote:
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.
That seems like a pretty niche requirement. In all of my years using Python I've never needed such a thing.
I suggest that when you need this functionality you create your own data structure combining a list and a collections.Counter and keep track of this yourself.