Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #106012
| 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 00:29:26 +0200 |
| Lines | 64 |
| Sender | forwardedby@e4ward.com |
| Message-ID | <mailman.169.1459290623.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> |
| Reply-To | mail.python.org@marco.sulla.e4ward.com |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de o1nWnQRFrl77ART7cgdO6wZ7AbsY+8x2lWr7ZNXHAerA== |
| Return-Path | <31489.gmail.com@bounce.e4ward.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.003 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'received:209.85.223': 0.03; 'pop': 0.05; 'method,': 0.07; 'shortcut': 0.07; 'dict': 0.09; 'immutable': 0.09; 'likewise': 0.09; 'mutable': 0.09; 'violates': 0.09; 'example:': 0.10; 'itself.': 0.11; 'index': 0.13; 'def': 0.13; '2016': 0.16; 'contract.': 0.16; 'mapping,': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'self[key]': 0.16; 'sequence,': 0.16; 'slice.': 0.16; 'stability.': 0.16; 'subject:interfaces': 0.16; 'subject:make': 0.16; 'wrote:': 0.16; 'why.': 0.18; '>>>': 0.20; 'changes': 0.20; 'arguments': 0.22; 'lawrence': 0.22; 'parameter': 0.22; 'tuples': 0.22; 'trying': 0.22; 'code,': 0.23; 'header:In-Reply-To:1': 0.24; "i've": 0.25; 'chris': 0.26; 'earlier': 0.27; 'point.': 0.27; 'checking': 0.27; 'message-id:@mail.gmail.com': 0.27; 'sequence': 0.27; 'idea': 0.28; 'interface': 0.29; 'closer': 0.29; 'figured': 0.29; 'index,': 0.29; 'key,': 0.29; 'separated': 0.29; 'array': 0.29; 'allows': 0.30; 'that.': 0.30; 'class.': 0.30; 'push': 0.30; 'useful': 0.33; 'class': 0.33; 'problem': 0.33; 'common': 0.33; 'items.': 0.33; 'programming,': 0.33; 'steven': 0.33; 'similar': 0.33; 'definition': 0.34; 'add': 0.34; 'received:google.com': 0.35; 'header:Received:8': 0.35; 'mapping': 0.35; 'stable': 0.35; 'item': 0.35; 'but': 0.36; 'should': 0.36; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'expect': 0.37; 'method': 0.37; 'received:209': 0.38; 'stuff': 0.38; 'why': 0.39; 'goes': 0.39; 'sure': 0.39; 'easily': 0.39; 'to:addr:python.org': 0.40; 'mark': 0.40; 'still': 0.40; 'some': 0.40; 'relationship': 0.61; "you'll": 0.61; 'subject:more': 0.61; 'further': 0.62; 'bring': 0.62; 'back': 0.62; 'making': 0.62; 'more': 0.63; 'march': 0.64; 'other.': 0.64; 'elsewhere': 0.66; 'safety': 0.66; 'header:Reply-To:1': 0.67; 'act': 0.67; 'reply-to:no real name:2**0': 0.71; 'distinguish': 0.84; 'lacks': 0.84; 'received:23': 0.84; 'terrible': 0.84; 'hand,': 0.97 |
| 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-type:content-type:subject:subject:message-id :date:date:from:from:references:in-reply-to:mime-version; s= mail; t=1459290614; x=1459377015; bh=B2tP86RcF7P7WOR+JG14DlJzUOU xlSHVQfVN60BPyTM=; b=Jat050IG8eUCv1NRDFparFOACzyq56Lap0nh6hs0ITC A6mfGirWhCh/+aG25WpgGKVDRcq8E6Z241aKlsNgKIqI4DByW0p4Znhm4tA+0BOz 41C1DwfVzYilKbc6JLWhZgi731fbatiqumZ6jYkmxbJy/jY82Vq9isAw2VefQJ7o = |
| 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; bh=B2tP86RcF7P7WOR+JG14DlJzUOUxlSHVQfVN60BPyTM=; b=zF6DzvCBTrkeVKAU9Fg61y5ltf0HBYS3STXPgj4qdCzrRh9T9kr0qmLa8ZP+zb3nuK WZj+CWZZDVyWO7ilEeuQ1hW3Y+B6BANWdKuwB/EA63EL+3c3KSOW5e1bxPVtz+In3OFh 83Ni15N3jGeQBIfoG/68d6MotUZFXbG9xJsRA7TLHCPE75njbfVRkntXBjaUJpef/4+4 zQW4xtquyoL68FmNMNCllGMRIr10g5+HrhoGU/eMKwOVj4FbfYWcfPU1IA0otqQuqJnG 0CqjkvaGlEia74xHnG0iHBwcP/0dsaH4E+WhvCskyr42TM6VOHpPLL8IG0yiORjPk1PW wyuw== |
| 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; bh=B2tP86RcF7P7WOR+JG14DlJzUOUxlSHVQfVN60BPyTM=; b=CrIx3ZY8RERZSHSfWWT3XQFZTkHJGTsRR5hYzgoClEdABgLhKeR77gBBHWPcN5fV3D jIvVTpQgT7VGiW+Ah9K8xix21o6ylRF45GtA+slpwVDPj82i14DKoIPtdvjq1fJ2+EKr Ua3oMaX+lYaZWGhxNO95WJkC+ke6dBkhdRbizxxIFjQM6xhEJfzTQDWq7kMKzQmMfvMj 9ruvl+gidPwfN4vJQihsIAOn9H7FU69eDAAnRNsjNflo27xxldnvT+c3Po+qJymbAYnJ jIKqetwPY9enY9nITNiO25hR0PdUwBIkGbJ0gzHxZWbzvPi0/r7a/+PiymxJwA/Y0CkT E+KQ== |
| X-Gm-Message-State | AD7BkJKnyorG/bemO5hlL0IQWDEK2R8P+i11IzeCdMYhrE36+7G5UIYjpRNfpHIPnJ2iZgqCPS+/nEHdimHWtw== |
| X-Received | by 10.107.132.149 with SMTP id o21mr5211915ioi.118.1459290606407; Tue, 29 Mar 2016 15:30:06 -0700 (PDT) |
| In-Reply-To | <CAPTjJmqjgnDvzS7=_YRf+T78GYz7J26FzWGfwrygYLeq2E9FeA@mail.gmail.com> |
| X-Google-Sender-Auth | w5St9Ueu2iXbLBT9mJ40x_0tZO0 |
| 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:106012 |
Show key headers only | View raw
On 29 March 2016 at 16:31, Chris Angelico <rosuav@gmail.com> wrote:
> But the definition of a sequence, and likewise the definition of a
> mapping, goes deeper than that. A sequence has *relative* stability;
> if one item is at a lower index than another, it will continue to be
> at a lower index, until you change one of those two items. Changes
> elsewhere in the sequence might bring them closer together or push
> them further apart, but one of them is still earlier in the sequence
> than the other. A mapping, on the other hand, has *absolute*
> stability. Any given key->value relationship is stable in and of
> itself. If you stuff a thing into a dict under a particular key, you
> expect to be able to get it back using that key, not some other.
It's the same arguments of Steven D'Aprano. Let me counter these
arguments with this example:
>>> class StrangeDict(dict):
... def insert(self, k, v):
... if k in self:
... for key in [x for x in sorted(self.keys()) if x >= k]:
... v_next = self[key]
... self[key] = v
... v = v_next
...
... self[key+1] = v
...
>>> a = StrangeDict({0:5, 1:7, 2: 14})
>>> a.insert(1, 5)
>>> a
{0: 5, 1: 5, 2: 7, 3: 14}
Yes, it's a terrible class and lacks a lot of safety checks, but I
don't think at all it violates the map contract. You can continue and
add some constraint at __init__() about key types and their
contiguity, some other methods and voila', you'll get a list-like
class.
Let me add that an items() and keys() for sequences will be also
useful for day-by-day programming, since they will be a shortcut for
enumerate(seq) and range(len(seq))
> The whole idea of making sequences and mappings more similar is highly
> distasteful to me, and I've figured out why. It's the exact problem
> with the PHP array - it's not sure whether to act as a mapping or a
> sequence
This is a good point. This is not true for mutable sequences (lists),
since they will have a lot of methods (append, pop etc) that allows
you to distinguish them, but immutable sequences like tuples will be
not easily distinguishable using duck typing.
I think the main problem is in __getitem__. __getitem__ can be used as
slice method checking if its parameter is a slice. If the slice method
was a separated method, this problem will not arise.
On 27 March 2016 at 21:24, Mark Lawrence <breamoreboy@yahoo.co.uk> wrote:
> Why do you need a new interace if all you're trying to do is create a
> vdict class that has "iter(d) == iter(d.values()), and should also
> have a count() method, like sequence types"?
Since simply adding get(), items(), keys(), values() to existing
sequence interface will likely break existing code, I would try also
to write new sequence types, using a common interface with maps. This
is my idea.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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