Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Marko Rauhamaa Newsgroups: comp.lang.python Subject: Re: Suggestion: make sequence and map interfaces more similar Date: Thu, 31 Mar 2016 15:36:24 +0300 Organization: A noiseless patient Spider Lines: 50 Message-ID: <87poualt87.fsf@elektro.pacujo.net> References: <56fb677f$0$11121$c3e8da3@news.astraweb.com> <56fba7d3$0$1616$c3e8da3$5496439d@news.astraweb.com> <56fbc518$0$1593$c3e8da3$5496439d@news.astraweb.com> <56fbf73d$0$1591$c3e8da3$5496439d@news.astraweb.com> <56fc8e09$0$1600$c3e8da3$5496439d@news.astraweb.com> <56fcfdc6$0$1612$c3e8da3$5496439d@news.astraweb.com> <56FD086F.2090301@rece.vub.ac.be> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="b7cb1518d23ec19d482dcc9c31d30fdd"; logging-data="4537"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+MBozyZA6flKqNzgEd0ECv" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) Cancel-Lock: sha1:AWkNezqs2iAd7q9k0O3pBkkSOPo= sha1:9LwW/qaCaS/6uh13jfufb3pc9DI= Xref: csiph.com comp.lang.python:106149 Chris Angelico : > On Thu, Mar 31, 2016 at 10:22 PM, Antoon Pardon > wrote: > Okay. I'll put a slightly different position: Prove that your proposal > is worth discussing by actually giving us an example that we can > discuss. Sorry for missing most of the arguments here, but if you are talking about treating lists as special cases of dicts, I have occasionally instinctively wanted something like this: >>> fields = [ "x", "y", "z" ] >>> selector = (1, 1, 0) >>> list(map(fields.get, selector)) Traceback (most recent call last): File "", line 1, in AttributeError: 'list' object has no attribute 'get' analogously with: >>> field_dict = { 0: "x", 1: "y", 2: "z" } >>> list(map(field_dict.get, selector)) ['y', 'y', 'x'] Or course, I could: >>> list(map(fields.__getitem__, selector)) ['y', 'y', 'x'] but that would abuse a dunder method. So I will need to: >>> list(map(lambda i: fields[i], selector)) ['y', 'y', 'x'] or (most likely): >>> new_fields = [] >>> for i in selector: ... new_fields.append(fields[i]) ... >>> new_fields ['y', 'y', 'x'] This tiny problem of mine could be remedied by adding a get method to lists. Marko