Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80348

Re: Real-world use of Counter

References <mailman.15504.1415204817.18130.python-list@python.org> <f28f7279-ac82-4a14-a433-561daec1efb2@googlegroups.com> <CALwzidk=Fwh51e_BEK50Laie+FCdYD+u4n-26wKQQVJYAMR0Hg@mail.gmail.com>
Date 2014-11-06 22:05 -0700
Subject Re: Real-world use of Counter
From Ian Kelly <ian.g.kelly@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.15553.1415337021.18130.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On Nov 6, 2014 10:51 AM, "Ian Kelly" <ian.g.kelly@gmail.com> wrote:
>
> On Nov 6, 2014 1:06 AM, "Rustom Mody" <rustompmody@gmail.com> wrote:
> > Calling a bag as counter is inappropriate for an analogous reason
> > to why calling a dictionary as a 'hash' is inappropriate --
> > it confuses an implementation detail for fundamental semantics.
>
> I've never liked the term "bag". In addition to being nonstandard it's
also very nonintuitive. "Multiset" is fine, except that it implies the
collection is a type of set, which the Python Counter is not.

I was thinking about this today, and it seems to me that the Python Counter
is not really even a multiset.

* The size of a multiset would be the count of all the elements; the len of
a Counter is only the number of keys.
* The multiplicity of an element in a multiset is restricted to the natural
numbers; the count of an element in a Counter can be any integer, even
negative.
* In a Counter, a key with a count of 0 is a distinct state from a key not
being present at all; in the latter case the element is not in the Counter,
while in the former case it *is* in the Counter. These states are also
distinct for the purpose of equality.

Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Real-world use of Counter Ethan Furman <ethan@stoneleaf.us> - 2014-11-05 08:26 -0800
  Re: Real-world use of Counter Rustom Mody <rustompmody@gmail.com> - 2014-11-05 22:00 -0800
    Re: Real-world use of Counter Ian Kelly <ian.g.kelly@gmail.com> - 2014-11-06 08:51 -0700
    Re: Real-world use of Counter Ian Kelly <ian.g.kelly@gmail.com> - 2014-11-06 22:05 -0700

csiph-web