> Thomas Heller writes: > > I was thinking of a popitem() dictionary method taking > > (optionally) 2 arguments: the name of the item to pop, > > and the default value to return if the item is not present > From: "Fred L. Drake, Jr." <fdrake@acm.org> > A one-arg version of the {}.popitem() method was discussed > extensively, but some people did not think it sufficiently useful to > include that variation. (I don't think anyone suggested a 2-arg > version at the time.) I tried to look it up in the archives. Although (because?) there are lots of messages about popitem() I cannot locate the relevant ones quick. > This certainly leads me to think the decision not to support a > one-arg version should be considered, or maybe a two-arg version. > However, I do expect the usage with args and without args are > substantially different. Perhaps there should be a different method > that has the one- and two-arg versions you describe, but does not > support the 0-arg semantics of the current popitem()? The catch is > that I'd name this popitem() as well. ;-) > Anyone else? After posting I noticed that {}.popitem() returns a (key, value) tuple. To make it absolutely clear (most of the time I'm not very lucky in explaining what I really want): What I mean is a {}.get(key, [value=None]) method, which returns the value, and removes the (key, value) pair from the dict if it is present. No idea how it should be named - since it does only return the value, popitem doesn't seem a good idea. Thomas
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4