[Python-ideas] data structures should have an .any() method

Gerald Britton gerald.britton at gmail.com
Sat Sep 5 15:26:34 CEST 2009


compose?  Where'd you find that?

On Sat, Sep 5, 2009 at 6:53 AM, Georg Brandl<g.brandl at gmx.net> wrote:
> Antoine Pitrou schrieb:
>> Nick Coghlan <ncoghlan at ...> 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))
>
> or
>
> any_item = compose(next, iter)
>
> ;)
>
> Georg
>
> --
> Thus spake the Lord: Thou shalt indent with four spaces. No more, no less.
> Four shall be the number of spaces thou shalt indent, and the number of thy
> indenting shall be four. Eight shalt thou not indent, nor either indent thou
> two, excepting that thou then proceed to four. Tabs are right out.
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>



-- 
Gerald Britton



More information about the Python-ideas mailing list