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

Steven D'Aprano steve at pearwood.info
Sat Sep 5 11:47:46 CEST 2009


On Fri, 4 Sep 2009 10:01:28 pm Matteo Dell'Amico wrote:

> Why? next(iter(obj)) means, pretty explicitly to me, "iterate on obj
> and give me one element".

To me, it says "give me the first element", not "give me any (an 
arbitrary) element" or "give me a random element".

Does anyone have a use-case for retrieving a single arbitrary element of 
an arbitrary sequence, without caring about any other elements? Is this 
really such a common operation that we need to consider it part of the 
interface for all collections? I doubt it.




-- 
Steven D'Aprano



More information about the Python-ideas mailing list