[Python-ideas] clear() method for lists
Masklinn
masklinn at masklinn.net
Fri Feb 12 11:05:08 CET 2010
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.
Though I'm not sure it's a very good idea for lists. Semantically, lists are to be iterated, not really to be indexed.
More information about the Python-ideas
mailing list