
Chris Bergstresser schrieb:
On Tue, Oct 27, 2009 at 11:06 AM, Georg Brandl g.brandl@gmx.net wrote:
Sorry to nitpick, but there is no list.get().
No? How ... odd. I guess it wouldn't have come up, but I was sure there was a .get method which took an optional default parameter if the index didn't exist, mirroring the dict method. Still, I think my point stands--it's a clear extrapolation from the existing dict.get().
I don't see that. Both dict.get() and your hypothetical list.get() are variants of the [] subscription operator, i.e. __getitem__, that have a default value, defaulting to None. The [] operator retrieves an element from the object at the specified "position", be it dict key, list index or some other abstract position.
Contrary to that, sets don't support subscript access, there is no notion of a value at a specified position, so I would find the set.get() naming confusing.
Georg