Proposed new collection methods
jeffrey.schwab at rcn.com
Sun Aug 7 06:08:09 CEST 2005
Robert Kern wrote:
> Robert Kern wrote:
>> Christopher Subich wrote:
>>> Dear Zeus no. Find can be defined as:
>>> def find(self, test=lambda x:1):
>>> item = (s for s in iter(self) if test(s)).next()
>>> except StopIteration:
>>> raise ValueError('No matching items in list')
>> I would prefer that a find() operation return as soon as it locates an
>> item that passes the test. This generator version tests every item.
> Pardon me, I am retarded.
Why are you retarded? Isn't the above code O(n)?
Forgive me for not understanding, I'm still awfully new to Python
(having come from Perl & C++), and I didn't see an explanation in the FAQ.
More information about the Python-list