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.
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).