<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Sep 30, 2015 at 9:53 AM, Neil Girdhar <span dir="ltr"><<a href="mailto:mistersheik@gmail.com" target="_blank">mistersheik@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Can you help understand how this is a Liskov substitution violation?  A Sequence is an Iterator.  Getting the sequence back should never hurt. </div></blockquote><div><br></div><div>no but getting a non-sequence iterator back when you expect a sequence sure can hurt.</div><div><br></div><div>which is why I said that if you want a sequence back from enumerate, it should always return a sequence. which could (should) be lazy-evaluated.</div><div><br></div><div>I think Neil's point is that calling list() or tuple() on it requires that the entire sequence be evaluated and stored -- if you really only want one item (and especially not one at the end), that could be a pretty big performance hit.</div><div><br></div><div>Which makes me wonder why ALL iterators couldn't support indexing? It might work like crap in some cases, but wouldn't it always be as good or better than wrapping it in a tuple? And then some cases (like enumerate) could do an index operation efficiently when they are working with "real" sequences.</div><div><br></div><div>Maybe a generic lazy_sequence object that could be wrapped around an iterator to create a lazy-evaluating sequence??</div><div><br></div><div>-CHB</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div class="h5"><br><div class="gmail_quote"><div dir="ltr">On Wed, Sep 30, 2015 at 12:43 PM Brett Cannon <<a href="mailto:brett@python.org" target="_blank">brett@python.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Wed, 30 Sep 2015 at 09:38 Neil Girdhar <<a href="mailto:mistersheik@gmail.com" target="_blank">mistersheik@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">In fairness, one is a superset of the other.  You always get an Iterable.  You sometimes get a Sequence.  It's a bit like multiplication? with integers you get integers, with floats, you get floats.</div></blockquote><div><br></div></div></div><div dir="ltr"><div class="gmail_quote"><div>No, it's not like multiplication. =) I hate saying this since I think it's tossed around too much, but int/float substitution doesn't lead to a Liskov substitution violation like substituting out a sequence for an iterator (which is what will happen if the type of the argument to `enumerate` changes). And since you can just call `list` or `tuple` on enumerate and get exactly what you're after without potential bugs cropping up if you don't realize from afar you're affecting an assumption someone made, I'm -1000 on this idea.</div></div></div><div dir="ltr"><div class="gmail_quote"><div><br></div><div>-Brett</div></div></div><div dir="ltr"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br><div class="gmail_quote"><div dir="ltr">On Wed, Sep 30, 2015 at 12:35 PM Brett Cannon <<a href="mailto:brett@python.org" target="_blank">brett@python.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Wed, 30 Sep 2015 at 08:28 Neil Girdhar <<a href="mailto:mistersheik@gmail.com" target="_blank">mistersheik@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">What are the pros and cons of making enumerate a sequence if its argument is a sequence?<div><font><font><br></font></font></div><div><font><font>I found myself writing:</font></font></div><div><font><font><font><font><br></font></font></font></font></div><div><font><font><font><font><div>                for vertex, height in zip(</div><div>                        self.cache.height_to_vertex[height_slice],</div><div>                        range(height_slice.start, height_slice.stop)):</div><div><br></div><div>I would have preferred:</div><div><br></div><div><div>                for height, vertex in enumerate(</div><div>                        self.cache.height_to_vertex)[height_slice]:<br></div></div></font></font></font></font></div></div></blockquote><div><br></div></div></div><div dir="ltr"><div class="gmail_quote"><div>Because you now suddenly have different types and semantics of what enumerate() returns based on its argument which is easy to mess up if self.cache.height_to_vertex became an iterator object itself instead of a sequence object. It's also not hard to simply do `tuple(enumerate(...))` to get the exact semantics you want: TOOWTDI.</div><div><br></div><div>IOW all I see are cons. =) </div></div></div>
</blockquote></div>
</blockquote></div></div></blockquote></div></div></div></div>
<br>_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><br>Christopher Barker, Ph.D.<br>Oceanographer<br><br>Emergency Response Division<br>NOAA/NOS/OR&R            (206) 526-6959   voice<br>7600 Sand Point Way NE   (206) 526-6329   fax<br>Seattle, WA  98115       (206) 526-6317   main reception<br><br><a href="mailto:Chris.Barker@noaa.gov" target="_blank">Chris.Barker@noaa.gov</a></div>
</div></div>