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


Groups > comp.lang.python > #106109

Re: Suggestion: make sequence and map interfaces more similar

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Marco Sulla <mail.python.org@marco.sulla.e4ward.com>
Newsgroups comp.lang.python
Subject Re: Suggestion: make sequence and map interfaces more similar
Date Wed, 30 Mar 2016 21:35:59 +0200
Lines 59
Sender forwardedby@e4ward.com
Message-ID <mailman.224.1459366624.28225.python-list@python.org> (permalink)
References <CABbU2U_DsSC=6d0HOwgGnzQZ0=r6U2sf_zOJP0U_w7_i0RrOKQ@mail.gmail.com> <mailman.92.1459101740.28225.python-list@python.org> <56f8836b$0$1602$c3e8da3$5496439d@news.astraweb.com> <56FA8C71.4050306@rece.vub.ac.be> <CAPTjJmqjgnDvzS7=_YRf+T78GYz7J26FzWGfwrygYLeq2E9FeA@mail.gmail.com> <CABbU2U9m-35UqK5KqRj7Y_oLdq_dgH3_EScLb4Sf3UNB4oCgmQ@mail.gmail.com> <CAPTjJmp1x-5=gEwBB=n-kt6YeVd6OiN_BGh5tNoL7UPYNqKb8w@mail.gmail.com> <mailman.176.1459309120.28225.python-list@python.org> <56fb677f$0$11121$c3e8da3@news.astraweb.com> <lf5twjoo2w8.fsf@ling.helsinki.fi> <56fba7d3$0$1616$c3e8da3$5496439d@news.astraweb.com> <lf5h9fouumu.fsf@ling.helsinki.fi> <56fbc518$0$1593$c3e8da3$5496439d@news.astraweb.com> <mailman.203.1459343574.28225.python-list@python.org> <56fbf73d$0$1591$c3e8da3$5496439d@news.astraweb.com>
Reply-To mail.python.org@marco.sulla.e4ward.com
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
X-Trace news.uni-berlin.de qXSV0lNo2aroXqUvZCAfrAwdqbNtaPzxWmr2rS6icl4A==
Return-Path <25194.gmail.com@bounce.e4ward.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'behave': 0.09; 'dict': 0.09; 'rules.': 0.09; 'stable.': 0.09; 'exception': 0.13; 'index': 0.13; 'argument': 0.15; '2016': 0.16; 'arbitrary.': 0.16; 'disables': 0.16; 'hashable': 0.16; 'lookups': 0.16; 'mean,': 0.16; 'ordereddict': 0.16; 'pairs': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'reedy': 0.16; 'subject:interfaces': 0.16; 'subject:make': 0.16; 'thinker,': 0.16; 'useless': 0.16; 'valid.': 0.16; 'wrote:': 0.16; 'basically': 0.18; 'implementing': 0.18; 'so.': 0.22; 'friend.': 0.22; 'keys': 0.22; 'code,': 0.23; 'insert': 0.23; 'sets': 0.23; 'header:In-Reply-To:1': 0.24; 'not.': 0.27; 'least': 0.27; 'message-id:@mail.gmail.com': 0.27; 'contract,': 0.27; 'finally,': 0.27; 'sequence': 0.27; 'values': 0.28; 'container': 0.29; 'extending': 0.29; 'methods.': 0.29; 'objects': 0.29; 'class.': 0.30; 'extend': 0.31; 'point': 0.33; 'class': 0.33; 'url:python': 0.33; "d'aprano": 0.33; 'ones,': 0.33; 'steven': 0.33; 'true.': 0.33; 'changing': 0.34; 'lists': 0.34; 'list': 0.34; 'received:google.com': 0.35; 'header:Received:8': 0.35; 'lists.': 0.35; 'mapping': 0.35; 'maps': 0.35; 'quite': 0.35; 'item': 0.35; 'supports': 0.35; 'but': 0.36; 'list,': 0.36; 'url:org': 0.36; 'received:209.85': 0.36; 'child': 0.36; 'url:library': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'expect': 0.37; 'method': 0.37; 'say': 0.37; 'received:209.85.213': 0.37; 'received:209': 0.38; 'does': 0.39; 'to:addr:python.org': 0.40; 'url:3': 0.60; 'your': 0.60; 'subject:more': 0.61; 'different': 0.63; 'march': 0.64; 'fall': 0.66; 'header:Reply-To:1': 0.67; 'act': 0.67; 'dear': 0.67; '8bit%:21': 0.70; 'reply-to:no real name:2**0': 0.71; 'concept.': 0.84; 'confusing': 0.84; 'received:23': 0.84; 'terrible': 0.84
Authentication-Results dfw.e4ward.com (amavisd-new); dkim=pass (1024-bit key) reason="pass (just generated, assumed good)" header.d=e4ward.com
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=e4ward.com; h= reply-to:content-transfer-encoding:content-type:content-type :subject:subject:message-id:date:date:from:from:references :in-reply-to:mime-version; s=mail; t=1459366609; x=1459453010; bh=qbkkN46AFlnUVvPDyGMvB6+90vdt5/FvkH8tPc9EJ7Q=; b=owPc8+uvXVp5 BoBKE+hCMPQn5NKPEW8uX/kvQtdwtddg2TAWxW4cKMrsmSLgjZbGpG0Nkg4WgTRg 1/b9BvUqxubew4V9H9acYWtCL1zImmL31NKTBR4QfaYm8bG8OIRYnDTF1Ldmwym6 IyVRtUJSz9POFQam6MFGiN/w7clynpo=
Authentication-Results dfw.e4ward.com (amavisd-new); dkim=fail (2048-bit key) reason="fail (message has been altered)" header.d=gmail.com
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:content-transfer-encoding; bh=qbkkN46AFlnUVvPDyGMvB6+90vdt5/FvkH8tPc9EJ7Q=; b=XWGo3A5uNDLP96B1ycgeirDmTOFGeK9TsGedSlmdBFkd4RT1WHhq3zTebNj+w64I+Q zLmF5WyCwb+QKWlfxGIplaC6eoQIp2lc9sQbDw6UWzHrEFcibThg2gJMwZcXjgkw3pEt EN1cKGUUi5oQLVYAplSbYdSo8cqh2G3ejsRnTsAUeM2oGzhn3dDA8zR+c5P5Nqz2T3ig dTFNO2Mx4TPH8DDywenW5gQ7Tot6ekvVgv+u3GLc0YiC8smBvWtQAl2IeBlXeu0yu+o3 AuBaAKb5vmXEszr6m4n2R4lQv1xHzd1rEa5QFzyiHM7o0r9ti3Vw4zgD/85U6i9qTpYO 2FTQ==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:content-transfer-encoding; bh=qbkkN46AFlnUVvPDyGMvB6+90vdt5/FvkH8tPc9EJ7Q=; b=efQ9VN3OVg6eOIG88ff0u6phvoytP4nKJ57+xrMcCCcM4rp45Fok7O6IoI7pWxxCef biLiTSun7FlexckFAsntryQ8Swb68MxnQ9ijzYT/ULzo7uHv773+H91W0SCpnO4kQ9+B zjOZD3wsXiks6kHUHAsJUDwJUdr9B5upczMq8Jlhf9WEBgBa5D+eQ4LfPz8pY8jqLk9O Bx0PlPQftQGZAVRHcQNd+lq3aKoqoP2T3eYlqw77f6Y8BfmEAPu71USWl+tIUB+VCJhV Y3ACo7Ze72I+rxS2/KjI/SR0XvstXOBDWr6HW7x88hI+rgGBA5+4jdVafmROyJ56cHbj vfow==
X-Gm-Message-State AD7BkJKNVbQZkJl/LCHBv06BOw6SMhVjtl/CYOV9HsiiSzNJnQEISWcVLXVVrA17SrpxUdrvbAkB45Uxl46Avg==
X-Received by 10.50.78.8 with SMTP id x8mr2266586igw.78.1459366598786; Wed, 30 Mar 2016 12:36:38 -0700 (PDT)
In-Reply-To <56fbf73d$0$1591$c3e8da3$5496439d@news.astraweb.com>
X-Google-Sender-Auth Z1ZlaDTP5PlLdq2DK-N8dhJf08g
X-e4ward-RCPT python-list.python.org-mail.python.org.marco.sulla.e4ward.com@ftcw4rx8877.reply.e4ward.com
X-e4ward-x .
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21
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>
Xref csiph.com comp.lang.python:106109

Show key headers only | View raw


On 30 March 2016 at 02:55, Terry Reedy <tjreedy@udel.edu> wrote:
> To me [seq.items() and seq.keys()] are useless and confusing duplications since enumerate()(seq)
> and range(len(seq)) are quite different from dict.items and dict.keys.

It's true. Indeed IMHO it's enumerate() that will be a confusing duplication.


On 30 March 2016 at 02:55, Terry Reedy <tjreedy@udel.edu> wrote:
> At least in CPython, changing a dict disables view iterators.

OrderedDict does not.


On 30 March 2016 at 07:43, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> This is not an argument about dicts being mutable, because clearly they
> aren't. This is an argument about key:value pairs being stable.


So you basically say "I expect to get the value x from key y". Let me
apply your point of view to lists. In lists, I expect to get the value
x from index y. If I insert an item in a position before index y, I
expect to get x at index y+1. But what if I write a class with a
method insertPlus() that sets None at y+1 and x at y+2? I can say it
does not violate the list contract, since you're extending the base
class and implementing a new method that is not present in base class.

If you extend a dict to act as a list, you're only adding
*constraints* to existing methods and adding new methods. You're not
completely change the existing ones, so the implementation is
perfectly valid.

Finally, let me quote the official docs:

A mapping object maps hashable values to arbitrary objects [...] A
dictionary’s keys are almost arbitrary values [...]
https://docs.python.org/3/library/stdtypes.html#dict

Mapping:A container object that supports arbitrary key lookups
https://docs.python.org/3/glossary.html#term-mapping

A sequence satisfies all these requirements, with the only exception
that keys are not arbitrary. But no one will tell you that a child
class that make a *restriction* over the original one will break
rules.

On 30 March 2016 at 17:56, Steven D'Aprano <steve@pearwood.info> wrote:
> If the OP wants to create his own "StrangeDict", which he himself described
> as "terrible", then he can do so. But to make all dicts and lists behave in
> this "terrible" and "strange" way is a terrible idea.

You did not understand well what I mean, my dear friend. I applied the
word "terrible" to my code, not to the concept. You've demonstrated
that a fair thinker, so do not fall in the temptation to play with
words.

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


Thread

Re: Suggestion: make sequence and map interfaces more similar "Marco S." <mail.python.org@marco.sulla.e4ward.com> - 2016-03-27 20:01 +0200
  Re: Suggestion: make sequence and map interfaces more similar Steven D'Aprano <steve@pearwood.info> - 2016-03-28 12:05 +1100
    Re: Suggestion: make sequence and map interfaces more similar Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2016-03-29 16:08 +0200
    Re: Suggestion: make sequence and map interfaces more similar Chris Angelico <rosuav@gmail.com> - 2016-03-30 01:31 +1100
    Re: Suggestion: make sequence and map interfaces more similar Marco Sulla <mail.python.org@marco.sulla.e4ward.com> - 2016-03-30 00:29 +0200
    Re: Suggestion: make sequence and map interfaces more similar Terry Reedy <tjreedy@udel.edu> - 2016-03-29 20:55 -0400
    Re: Suggestion: make sequence and map interfaces more similar Chris Angelico <rosuav@gmail.com> - 2016-03-30 11:56 +1100
    Re: Suggestion: make sequence and map interfaces more similar Random832 <random832@fastmail.com> - 2016-03-29 23:38 -0400
      Re: Suggestion: make sequence and map interfaces more similar Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-03-30 16:43 +1100
        Re: Suggestion: make sequence and map interfaces more similar Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-03-30 16:57 +1100
        Re: Suggestion: make sequence and map interfaces more similar Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-03-30 10:12 +0300
          Re: Suggestion: make sequence and map interfaces more similar Steven D'Aprano <steve@pearwood.info> - 2016-03-30 21:17 +1100
            Re: Suggestion: make sequence and map interfaces more similar Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-03-30 13:28 +0300
              Re: Suggestion: make sequence and map interfaces more similar Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2016-03-30 12:34 +0200
                Re: Suggestion: make sequence and map interfaces more similar Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-03-30 13:57 +0300
              Re: Suggestion: make sequence and map interfaces more similar Steven D'Aprano <steve@pearwood.info> - 2016-03-30 23:22 +1100
                Re: Suggestion: make sequence and map interfaces more similar Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2016-03-30 15:12 +0200
                Re: Suggestion: make sequence and map interfaces more similar Steven D'Aprano <steve@pearwood.info> - 2016-03-31 02:56 +1100
                Re: Suggestion: make sequence and map interfaces more similar Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2016-03-30 21:07 +0200
                Re: Suggestion: make sequence and map interfaces more similar Steven D'Aprano <steve@pearwood.info> - 2016-03-31 13:40 +1100
                Re: Suggestion: make sequence and map interfaces more similar Paul Rubin <no.email@nospam.invalid> - 2016-03-30 19:45 -0700
                Re: Suggestion: make sequence and map interfaces more similar Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-03-31 17:45 +1100
                Re: Suggestion: make sequence and map interfaces more similar Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2016-03-31 09:52 +0200
                Re: Suggestion: make sequence and map interfaces more similar Steven D'Aprano <steve@pearwood.info> - 2016-03-31 21:36 +1100
                Re: Suggestion: make sequence and map interfaces more similar Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2016-03-31 12:51 +0200
                Re: Suggestion: make sequence and map interfaces more similar Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2016-03-31 13:22 +0200
                Re: Suggestion: make sequence and map interfaces more similar Chris Angelico <rosuav@gmail.com> - 2016-03-31 22:57 +1100
                Re: Suggestion: make sequence and map interfaces more similar Marko Rauhamaa <marko@pacujo.net> - 2016-03-31 15:36 +0300
                Re: Suggestion: make sequence and map interfaces more similar Chris Angelico <rosuav@gmail.com> - 2016-03-31 23:48 +1100
                Re: Suggestion: make sequence and map interfaces more similar Marko Rauhamaa <marko@pacujo.net> - 2016-03-31 17:02 +0300
                Re: Suggestion: make sequence and map interfaces more similar Michael Selik <michael.selik@gmail.com> - 2016-04-01 04:19 -0400
                Re: Suggestion: make sequence and map interfaces more similar Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-03-31 15:55 +0300
                Re: Suggestion: make sequence and map interfaces more similar Marko Rauhamaa <marko@pacujo.net> - 2016-03-31 17:19 +0300
                Re: Suggestion: make sequence and map interfaces more similar Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2016-03-31 15:08 +0200
                Re: Suggestion: make sequence and map interfaces more similar Rustom Mody <rustompmody@gmail.com> - 2016-03-31 06:42 -0700
                Re: Suggestion: make sequence and map interfaces more similar Chris Angelico <rosuav@gmail.com> - 2016-04-01 00:11 +1100
                Re: Suggestion: make sequence and map interfaces more similar Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-31 14:17 +0100
                Re: Suggestion: make sequence and map interfaces more similar Random832 <random832@fastmail.com> - 2016-03-31 09:27 -0400
                Re: Suggestion: make sequence and map interfaces more similar Marko Rauhamaa <marko@pacujo.net> - 2016-03-31 17:13 +0300
                Re: Suggestion: make sequence and map interfaces more similar Terry Reedy <tjreedy@udel.edu> - 2016-03-31 13:41 -0400
                Re: Suggestion: make sequence and map interfaces more similar Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-31 15:12 +0100
                Re: Suggestion: make sequence and map interfaces more similar Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2016-04-01 09:59 +0200
                Re: Suggestion: make sequence and map interfaces more similar Tim Golden <mail@timgolden.me.uk> - 2016-04-01 09:27 +0100
                Re: Suggestion: make sequence and map interfaces more similar Steven D'Aprano <steve@pearwood.info> - 2016-04-01 21:38 +1100
                Re: Suggestion: make sequence and map interfaces more similar Marko Rauhamaa <marko@pacujo.net> - 2016-04-01 13:50 +0300
                Re: Suggestion: make sequence and map interfaces more similar Rustom Mody <rustompmody@gmail.com> - 2016-04-01 07:41 -0700
                Re: Suggestion: make sequence and map interfaces more similar Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-04-01 10:04 +0100
                Re: Suggestion: make sequence and map interfaces more similar Marco Sulla <mail.python.org@marco.sulla.e4ward.com> - 2016-03-30 21:35 +0200
                Re: Suggestion: make sequence and map interfaces more similar Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-30 21:31 +0100
            Re: Suggestion: make sequence and map interfaces more similar Manolo Martínez <manolo@austrohungaro.com> - 2016-03-30 12:26 +0200
              Re: Suggestion: make sequence and map interfaces more similar Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-03-30 13:40 +0300
                Re: Suggestion: make sequence and map interfaces more similar Manolo Martínez <manolo@austrohungaro.com> - 2016-03-30 12:50 +0200
                Re: Suggestion: make sequence and map interfaces more similar Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-03-30 14:21 +0300
                Re: Suggestion: make sequence and map interfaces more similar Marko Rauhamaa <marko@pacujo.net> - 2016-03-30 14:44 +0300
                Re: Suggestion: make sequence and map interfaces more similar Manolo Martínez <manolo@austrohungaro.com> - 2016-03-30 14:29 +0200
                Re: Suggestion: make sequence and map interfaces more similar Marko Rauhamaa <marko@pacujo.net> - 2016-03-30 15:55 +0300
                Re: Suggestion: make sequence and map interfaces more similar Manolo Martínez <manolo@austrohungaro.com> - 2016-03-30 15:13 +0200
                Re: Suggestion: make sequence and map interfaces more similar Steven D'Aprano <steve@pearwood.info> - 2016-03-30 23:27 +1100
                Re: Suggestion: make sequence and map interfaces more similar Marko Rauhamaa <marko@pacujo.net> - 2016-03-30 15:48 +0300
                Re: Suggestion: make sequence and map interfaces more similar Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-03-30 17:38 +0300
                Re: Suggestion: make sequence and map interfaces more similar Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-03-30 17:25 +0300
        Re: Suggestion: make sequence and map interfaces more similar Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2016-03-30 10:55 +0200
        Re: Suggestion: make sequence and map interfaces more similar Random832 <random832@fastmail.com> - 2016-03-30 08:50 -0400
          Re: Suggestion: make sequence and map interfaces more similar Steven D'Aprano <steve@pearwood.info> - 2016-03-31 03:02 +1100
            Re: Suggestion: make sequence and map interfaces more similar Random832 <random832@fastmail.com> - 2016-03-30 12:52 -0400
              Re: Suggestion: make sequence and map interfaces more similar Steven D'Aprano <steve@pearwood.info> - 2016-03-31 13:44 +1100
                Re: Suggestion: make sequence and map interfaces more similar Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2016-03-31 10:04 +0200
                Re: Suggestion: make sequence and map interfaces more similar Marco Sulla <mail.python.org@marco.sulla.e4ward.com> - 2016-03-31 13:58 +0200
                Re: Suggestion: make sequence and map interfaces more similar Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-31 13:30 +0100
                Re: Suggestion: make sequence and map interfaces more similar Marco Sulla <mail.python.org@marco.sulla.e4ward.com> - 2016-03-31 14:49 +0200
                Re: Suggestion: make sequence and map interfaces more similar Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-31 14:14 +0100
            Re: Suggestion: make sequence and map interfaces more similar Marco Sulla <mail.python.org@marco.sulla.e4ward.com> - 2016-03-30 22:00 +0200
            Re: Suggestion: make sequence and map interfaces more similar Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-30 21:36 +0100
    Re: Suggestion: make sequence and map interfaces more similar Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-30 08:03 +0100

csiph-web