
Sept. 5, 2009
2:45 a.m.
Nick Coghlan <ncoghlan@...> writes:
Because it overspecifies the semantics of what you're trying to do. It just happens that when the requirement is "get me any object in this container" the design of Python means that the easiest implementation is "get me the first object in this container".
I don't agree. Since iteration is such a frequent operation, any container which doesn't provide cheap iteration could be considered badly designed and/or badly implemented. Therefore it makes sense to rely on iteration when implementing other primitives. People worrying that it expresses implementation rather than intent can write the trivial abstraction by themselves: def any_item(x): return next(iter(x)) Regards Antoine.