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

Stefan Behnel stefan_ml at behnel.de
Mon Sep 7 09:22:58 CEST 2009

Greg Ewing wrote:
> Steven D'Aprano wrote:
>> If you're expecting "exactly one result", then surely it should be an
>> error to receive more than one result? Rather than ask for "any"
>> result and ignoring any unexpected extra items, I think it would be
>> better to have a helper function that verifies you have got exactly
>> one result.
> Yes, that could be useful. Maybe call it "one"?

I think "one" fits two of the proposed three use cases pretty nicely. The
only remaining use case is where you actually have more than one item but
only want any one out of them. But I think in that case you can actually
roll your own anyway, as there may be other constrains on exactly how
'equal' all the items are.


More information about the Python-ideas mailing list