[issue11881] Add list.get

2011-04-22 Thread Éric Araujo

Changes by Éric Araujo mer...@netwok.org:


--
nosy: +eric.araujo

___
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



[issue11881] Add list.get

2011-04-19 Thread Filip Gruszczyński

New submission from Filip Gruszczyński grusz...@gmail.com:

I have proposed on Core Mentorship list to add get(index, default) method to 
list object. I was suggested to bring it up here and also told, that improving 
operator module could be a better solution. This is why I would like to ask, if 
it makes sense to work on this?

I attach a patch for list objects. I would post a link to Core Mentorship 
thread, but I believe the archive is private.

The original idea came from a question on StackOverflow: 
http://stackoverflow.com/questions/2492087/how-to-get-the-nth-element-of-a-python-list-or-a-default-if-not-available

--
components: Interpreter Core
files: list.get.patch
keywords: patch
messages: 134087
nosy: gruszczy
priority: normal
severity: normal
status: open
title: Add list.get
type: feature request
versions: Python 3.3
Added file: http://bugs.python.org/file21726/list.get.patch

___
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



[issue11881] Add list.get

2011-04-19 Thread Raymond Hettinger

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

Sorry, this has come up before and was rejected.

--
nosy: +rhettinger
resolution:  - rejected
status: open - closed

___
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



[issue11881] Add list.get

2011-04-19 Thread Raymond Hettinger

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

What did you have in mind for the operator module?

--

___
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



[issue11881] Add list.get

2011-04-19 Thread Filip Gruszczyński

Filip Gruszczyński grusz...@gmail.com added the comment:

Nick Coghlan suggested, that operator.getitem could be extended to accept 
default value. How does it sound to you?

--

___
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



[issue11881] Add list.get

2011-04-19 Thread Raymond Hettinger

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