[Python-ideas] getitem(obj, key, default) [was: Default return values to int and float]

Raymond Hettinger raymond.hettinger at gmail.com
Tue Oct 4 04:04:56 CEST 2011


On Oct 3, 2011, at 7:24 PM, Jan Kaliszewski wrote:

> Nick Coghlan dixit (2011-10-03, 13:03):
> 
>> I'd sooner see a getitem/3 builtin
>> that could be used to ignore any LookupError the way dict.get/3 allows
>> KeyError to be ignored.
> 
> +1.
> 
> It's probably quite common case.

How many times does this silly idea have to get shot down?
Do you see other languages implementing get defaults on sequences?
Do you see lots of python users implementing this in a util module because it is an important operation?
Can you find examples of real-world code that would be significantly improved with list.get() functionality?
Does this make any semantic sense to users (i.e. they specifically want to the i-th item of sequence but don't even know long the sequence is)?
Refuse to hypergeneralize dict.get() into a context where it doesn't make sense (it does make sense for mappings, but not for sequences; sequence indices are all about position while mapping keys have deeper relationship to the corresponding values).


Raymond





More information about the Python-ideas mailing list