A RetroSearch Logo

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

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/1999-July/000563.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 secondJim Fulton jim@digicool.com
Thu, 22 Jul 1999 12:49:33 -0400
Gordon McMillan wrote:
> 
> Offhand I can't think of a built-in that can't be expressed in normal
> Python notation, where "optional" args are really defaulted args.

I can define the pop I want in Python as follows:

  _marker=[]

  class list:
     ...
     def pop(index=-1, default=marker):
          try: v=self[index]
          except IndexError:
              if default is not marker: 
                  return default
              if self: m='pop index out of range'
	      else:    m='pop from empty list'
              raise IndexError, m
          del self[index]
          return v

Although I'm not sure why the "pythonicity" of an
interface should depend on it's implementation.
 
Jim

--
Jim Fulton           mailto:jim@digicool.com   Python Powered!        
Technical Director   (888) 344-4332            http://www.python.org  
Digital Creations    http://www.digicool.com   http://www.zope.org    

Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
address may not be added to any commercial mail list with out my
permission.  Violation of my privacy with advertising or SPAM will
result in a suit for a MINIMUM of $500 damages/incident, $1500 for
repeats.



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