11 Jan
2014
11 Jan
'14
4:03 p.m.
On Sun, Jan 12, 2014 at 8:47 AM, Mathias Panzenböck
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