<div dir="ltr">It is pretty inefficient. As for getting the last item, however, I think something like that might end up the best.<div><br></div><div>And, you've gotta admit, it isn't bad for a 30-second solution with no real planning whatsoever.</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Jan 11, 2014 at 4:03 PM, Chris Angelico <span dir="ltr"><<a href="mailto:rosuav@gmail.com" target="_blank">rosuav@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 class="im">On Sun, Jan 12, 2014 at 8:47 AM, Mathias Panzenböck<br>
<<a href="mailto:grosser.meister.morti@gmx.net">grosser.meister.morti@gmx.net</a>> wrote:<br>
> Why not:<br>
><br>
> get_first = lambda d: next(iter(d.items()))<br>
><br>
> No need for a full copy of the dict.<br>
><br>
><br>
> On 01/11/2014 09:51 PM, Ryan Gonzalez wrote:<br>
>><br>
>> Based on your popitem idea:<br>
>><br>
>> get_first = lambda d: d.copy().popitem()<br>
>> get_last = lambda d: d.copy().popitem(last=True)<br>
<br>
</div>Oh right. Yeah, copy(). So this isn't destructive, but as Mathias<br>
says, it's probably inefficient. (I say "probably" because it's<br>
theoretically possible to optimize the copy operation - but I don't<br>
see anything like that in the source code.)<br>
<div class="im HOEnZb"><br>
ChrisA<br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
</div><div class="HOEnZb"><div class="h5"><a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank">http://python.org/psf/codeofconduct/</a></div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr">Ryan<div><span style="color:rgb(0,0,0);font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;line-height:18px"><font>When your hammer is C++, everything begins to look like a thumb.</font></span><br>
</div></div>
</div>