Raymond Hettinger <raymond.hettin...@gmail.com> added the comment:

> operator.getitem could be extended to accept default value

That would be relatively harmless.  And because it isn't type specific to 
lists, it would be applicable to other types that might better use cases than 
lists do.

If you want to pursue this, please change the name of this tracker item and 
re-open it.

Do spend some time thinking about whether it is good language design.  Is 
"getitem(s, i, dft)" better than "s[i] if i < len(s) else dft" or list 
unpacking, etc.?  Various meanings of better include 1) the preferred way to do 
it, 2) a faster way to do it, 3) surrounding code reads significantly better 
using the new construct, and 4) it's worth taking the time to learn and 
remember it.  By adding this to the language, you're telling people that this 
is the RightThingToDo(tm).  

Programming this is easy -- the hard part is knowing whether it is worthwhile 
(a question on StackOverflow is not sufficient motivation).  You might also 
want to grep lots of real world code to see if there would be actual benefits 
to real code or whether it will end-up being cruft that we put in because it 
was easy and cute.  Python has had 20+ years of development without needing 
this, so it's worth really thinking about it before going ahead.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue11881>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to