It is pretty inefficient. As for getting the last item, however, I think
something like that might end up the best.
And, you've gotta admit, it isn't bad for a 30-second solution with no real
planning whatsoever.
On Sat, Jan 11, 2014 at 4:03 PM, Chris Angelico
On Sun, Jan 12, 2014 at 8:47 AM, Mathias Panzenböck
wrote: Why not:
get_first = lambda d: next(iter(d.items()))
No need for a full copy of the dict.
On 01/11/2014 09:51 PM, Ryan Gonzalez wrote:
Based on your popitem idea:
get_first = lambda d: d.copy().popitem() get_last = lambda d: d.copy().popitem(last=True)
Oh right. Yeah, copy(). So this isn't destructive, but as Mathias says, it's probably inefficient. (I say "probably" because it's theoretically possible to optimize the copy operation - but I don't see anything like that in the source code.)
ChrisA _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
-- Ryan When your hammer is C++, everything begins to look like a thumb.