
Masklinn wrote:
On 12 Feb 2010, at 10:58 , Nick Coghlan wrote:
George Sakkis wrote:
Speaking of new potential list methods, how about list.get(index, default=None) ala dict.get ? I'm sure this has must have come up at some point but can't find it ATM. I believe it runs afoul of the moratorium, but a getitem() builtin might be a better idea (since it would then work for any class that implements __getitem__).
Maybe just extending operator.itemgetter with a "default" kwarg? Wouldn't run afoul the moratorium, and would be quite a nice extension to itemgetter.
Yeah, a kw-only arg for itemgetter and attrgetter could definitely work. It would be somewhat clunky to use though.
Though I'm not sure it's a very good idea for lists. Semantically, lists are to be iterated, not really to be indexed.
Using short lists as record sets happens all the time (especially with things like str.split and other parsing operations that build up their results incrementally). Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia ---------------------------------------------------------------