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


Groups > comp.lang.python > #80348

Re: Real-world use of Counter

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.016
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'element': 0.07; '*is*': 0.09; 'latter': 0.09; 'negative.': 0.09; 'python': 0.11; 'distinct': 0.16; 'equality.': 0.16; 'implies': 0.16; 'integer,': 0.16; 'keys.': 0.16; 'multiset.': 0.16; 'numbers;': 0.16; 'set,': 0.16; 'wrote:': 0.18; 'seems': 0.21; 'email addr:gmail.com&gt;': 0.22; "i've": 0.25; '&gt;': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'fine,': 0.31; 'restricted': 0.31; 'not.': 0.33; 'except': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'detail': 0.37; 'being': 0.38; 'skip:& 10': 0.38; 'nov': 0.38; 'to:addr:python- list': 0.38; 'skip:& 20': 0.39; 'to:addr:python.org': 0.39; 'even': 0.60; 'liked': 0.60; 'today,': 0.61; 'term': 0.63; 'skip:n 10': 0.64; 'natural': 0.68; 'bag': 0.74; 'all;': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=L1tiNljTNNt5ZcffH8Ud64mge1lZ032LwMpsDlcJW1k=; b=0KDajXkQ2dGc4phKg9ngbLQSeQE0Sea7HEV44eh7Yu6IThBagtEZfOdTV2hCrbYIGa /cs0Cc+PIQAEoCFNcEiI67jyvv3HpbEx+dsb5LPe9fQtwHiXp1kqXfzcUvC0+WWXikPa qspbh5TAY4xpMYvHxLMqdR17UQf875NbwXW7EkoTITB/h1Ccs1biEgLd5xJfV81cPr08 7emEtyOQrDN42McodkGqNxJ8YZpHKdwKPBKloikV4z3AuFjETj3+baz9cMsLlBFUizMv j+QhA/zyxvKEn06ekeDoComOJuq5uBONdOSWiCr0s8mNo2uRx8M+ZRADDut5auo7mvQw psHg==
MIME-Version 1.0
X-Received by 10.66.146.71 with SMTP id ta7mr9726565pab.16.1415336700728; Thu, 06 Nov 2014 21:05:00 -0800 (PST)
In-Reply-To <CALwzidk=Fwh51e_BEK50Laie+FCdYD+u4n-26wKQQVJYAMR0Hg@mail.gmail.com>
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 Thu, 6 Nov 2014 22:05:00 -0700
Subject Re: Real-world use of Counter
From Ian Kelly <ian.g.kelly@gmail.com>
To Python <python-list@python.org>
Content-Type multipart/alternative; boundary=047d7b6da6ee48dc1e05073dc1c5
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.15553.1415337021.18130.python-list@python.org> (permalink)
Lines 61
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1415337021 news.xs4all.nl 2860 [2001:888:2000:d::a6]:51196
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:80348

Show key headers only | 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