<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Feb 20, 2017 at 12:54 PM, Ryan Gonzalez <span dir="ltr"><<a href="mailto:rymg19@gmail.com" target="_blank">rymg19@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><div dir="auto">elements = [mylist[a], mylist[b]]</div><div dir="auto">- Right now, a[b,c] is already valid syntax, since it's just indexing a with the tuple (b, c). The proposal is to make this a specialization in the grammar, and also allow stuff like a[b:c, d:e] (like `a.__getitem__(slice(b, c), slice(d, e))`).<br></div><div dir="auto"></div></div></blockquote><div><br></div><div>This part is DOA.  As someone else notes, use of tuples as indexers is commonplace in NumPy (and Pandas, XArray, Dask, etc).  In those collection types, the comma refers to dimensions of the data.</div><div><br></div><div>However, as someone else notes, you can create whatever meaning you want for indexing with a tuple.  I think it would be confusing to give a meaning very different from that in NumPy; but it's perfectly syntactical.</div><div><br></div></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_extra"><div class="gmail_quote"><div><font face="monospace, monospace" size="1">class MultisliceList(list):</font></div><div><font face="monospace, monospace" size="1">    def __getitem__(self, arg):</font></div><div><font face="monospace, monospace" size="1">        if isinstance(arg, int) or isinstance(arg, slice):</font></div><div><font face="monospace, monospace" size="1">            return list.__getitem__(self, arg)</font></div><div><font face="monospace, monospace" size="1">        elif isinstance(arg, tuple):</font></div><div><font face="monospace, monospace" size="1">            indices = set()</font></div><div><font face="monospace, monospace" size="1">            for x in arg:</font></div><div><font face="monospace, monospace" size="1">                if isinstance(x, int):</font></div><div><font face="monospace, monospace" size="1">                    indices.add(x)</font></div><div><font face="monospace, monospace" size="1">                elif isinstance(x, slice):</font></div><div><font face="monospace, monospace" size="1">                    for i in range(x.start or 0, x.stop, x.step or 1):</font></div><div><font face="monospace, monospace" size="1">                        indices.add(i)</font></div><div><font face="monospace, monospace" size="1">                else:</font></div><div><font face="monospace, monospace" size="1">                    raise NotImplementedError("Can only index with ints and slices")</font></div><div><font face="monospace, monospace" size="1">        else:</font></div><div><font face="monospace, monospace" size="1">            raise NotImplementedError("Can only index with ints and slices")</font></div><div><font face="monospace, monospace" size="1"><br></font></div><div><font face="monospace, monospace" size="1">        return MultisliceList([list.__getitem__(self, i) for i in sorted(indices)]))<br></font></div><div><font face="monospace, monospace" size="1"><br></font></div><div><font face="monospace, monospace" size="1">>>> l = MultisliceList(range(1000,0,-5))</font></div><div><font face="monospace, monospace" size="1">>>> l[10:15], type(l[10:15])</font></div><div><pre style="box-sizing:border-box;overflow:auto;padding:0px;margin-top:0px;margin-bottom:0px;line-height:inherit;word-break:break-all;word-wrap:break-word;color:rgb(0,0,0);border:0px;border-radius:0px;white-space:pre-wrap;vertical-align:baseline"><font face="monospace, monospace" size="1">([950, 945, 940, 935, 930], list)</font></pre><pre style="box-sizing:border-box;overflow:auto;padding:0px;margin-top:0px;margin-bottom:0px;line-height:inherit;word-break:break-all;word-wrap:break-word;color:rgb(0,0,0);border:0px;border-radius:0px;white-space:pre-wrap;vertical-align:baseline"><font face="monospace, monospace" size="1">>>> l[9], type(l[9])</font></pre><pre style="box-sizing:border-box;overflow:auto;padding:0px;margin-top:0px;margin-bottom:0px;line-height:inherit;word-break:break-all;word-wrap:break-word;color:rgb(0,0,0);border:0px;border-radius:0px;white-space:pre-wrap;vertical-align:baseline"><pre style="box-sizing:border-box;overflow:auto;padding:0px;margin-top:0px;margin-bottom:0px;line-height:inherit;word-break:break-all;word-wrap:break-word;border:0px;border-radius:0px;white-space:pre-wrap;vertical-align:baseline"><font face="monospace, monospace" size="1">(955, int)</font></pre><pre style="box-sizing:border-box;overflow:auto;padding:0px;margin-top:0px;margin-bottom:0px;line-height:inherit;word-break:break-all;word-wrap:break-word;border:0px;border-radius:0px;white-space:pre-wrap;vertical-align:baseline"><font face="monospace, monospace" size="1">>>> msl = l[9,110:115,10:15,100]
>>> msl, type(msl)</font></pre><pre style="box-sizing:border-box;overflow:auto;padding:0px;margin-top:0px;margin-bottom:0px;line-height:inherit;word-break:break-all;word-wrap:break-word;border:0px;border-radius:0px;white-space:pre-wrap;vertical-align:baseline"><font face="monospace, monospace" size="1">([955, 950, 945, 940, 935, 930, 500, 450, 445, 440, 435, 430],
 __main__.MultisliceList)</font></pre></pre></div></div></div></blockquote><div class="gmail_extra"><div><br></div><div><br></div><div>I decided that the various index positions indicated should be in sorted order (there might be overlap in tuple items).  Also I didn't make a single slice stay as the special class. You can write your version however you like.</div><div><br></div>-- <br><div class="gmail-m_-7855224051840471301gmail_signature">Keeping medicines from the bloodstreams of the sick; food <br>from the bellies of the hungry; books from the hands of the <br>uneducated; technology from the underdeveloped; and putting <br>advocates of freedom in prisons.  Intellectual property is<br>to the 21st century what the slave trade was to the 16th.<br></div>
</div></div>