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

Greg Ewing greg.ewing at canterbury.ac.nz
Sun Sep 6 07:45:34 CEST 2009


Stefan Behnel wrote:

> It would therefore be nice to have a common ".any()" method on data
> structures that would just read an arbitrary item from a container.

Rather than add a method to every container implementation,
it would be easier to provide a function:

    def first(obj):
      return iter(ob).next()

possibly with some embellishments to handle StopIteration,
allow for a default value, etc.

-- 
Greg



More information about the Python-ideas mailing list