[Python-ideas] Proposal for extending the collections module - bags / multisets, ordered sets / unique lists

Jan Kaliszewski zuo at chopin.edu.pl
Sun Jul 19 20:51:56 CEST 2009


Mike Meyer <mwm-keyword-python.b4bdba at mired.org> wrote:

> On Sun, 19 Jul 2009 18:49:09 +1000
> Steven D'Aprano <steve at pearwood.info> wrote:
>
>> On Sun, 19 Jul 2009 05:47:28 pm Mike Meyer wrote:
>>
>> > > A dict or set having a count method would make no sense either.
>> > > This has nothing to do with polymorphism.
>> >
>> > Actually, count on a dict makes *lots* of sense. I can think of a lot
>> > of uses for counting the number of occurrences of values in a
>> > dictionary, mostly revolving around using dictionaries to implement
>> > sparse arrays of various kinds.
>>
>> But dicts don't allow you to look up on values, you look up on keys.
>
> So? I wasn't talking about looking up values, I was talking about
> counting them. Of course, lists don't do that very well either - you
> can only look up two values, or maybe it's one. And that's just
> another thing that makes changing an implementations from lists to dicts
>
>> dict.count(value) might be useful -- I doubt that there are "a lot of
>> uses", but there are probably a few -- but it's hardly a fundamental
>> operation on a dict. I'd argue it would be better as a function
>> count_value(mapping, value) rather than a method.

You seem to have forgot that now we have dict views.

I think it should be a method -- but of dict values-view rather than of
dict itself.

-- 
Jan Kaliszewski <zuo at chopin.edu.pl>



More information about the Python-ideas mailing list