A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/1999-July/000554.html below:

[Python-Dev] I'd like list.pop to accept an optional second

[Python-Dev] I'd like list.pop to accept an optional second [Python-Dev] I'd like list.pop to accept an optional secondGordon McMillan gmcm@hypernet.com
Thu, 22 Jul 1999 11:07:31 -0500
Jim Fulton writes:

> With pop, you can essentially test whether the list is 
> empty and get a value if it isn't in one atomic operation:
> 
>   try: 
>       foo=queue.pop(0)
>   except IndexError:
>       ... empty queue case
>   else:
>       ... non-empty case, do something with foo
> 
> Unfortunately, this incurs exception overhead. I'd rather do 
> something like:
> 
>   foo=queue.pop(0,marker)
>   if foo is marker: 
>       ... empty queue case
>   else:
>       ... non-empty case, do something with foo

I'm assuming you're asking for the equivalent of:
 def pop(self, default=None):
much like dict.get?

Then how do I get the old behavior? (I've been known to do odd 
things - like change behavior based on the number of args - in 
extension modules, but this ain't an extension).

- Gordon



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