"Mike Meyer" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Another thread pointed out a couple of methods that would be nice to
> have on Python collections: find and inject.
Since Python does not have a collections superclass, I am puzzled as to
what you are really proposing.
Jeff Schwab wrote:
> Robert Kern wrote:
>> Now, if I were to do
>>
>> item = g(self, test).next()
>>
>> the generator would execute the code until it reached the yield
>> statement which happens when it finds the first item that passes the
>> test. That item will get returned, and execution doe
Robert Kern wrote:
> Jeff Schwab wrote:
>> 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.
> (s for s in iter(self) is test(s)) is a generato
Robert Kern wrote:
> (s for s in iter(self) is test(s)) is a generator expression. It is
> roughly equivalent to
>
> def g(self, test=lambda x: True):
> for s in iter(self):
> if test(s):
> yield s
>
> Now, if I were to do
>
> item = g(self, test).next()
>
> the generato
Jeff Schwab wrote:
> Robert Kern wrote:
>
>>Robert Kern wrote:
>>
>>>Christopher Subich wrote:
>>>
Dear Zeus no. Find can be defined as:
def find(self, test=lambda x:1):
try:
item = (s for s in iter(self) if test(s)).next()
except StopIteration:
raise Val
Robert Kern wrote:
> Robert Kern wrote:
>
>> Christopher Subich wrote:
>>
>>
>>> Dear Zeus no. Find can be defined as:
>>> def find(self, test=lambda x:1):
>>>try:
>>> item = (s for s in iter(self) if test(s)).next()
>>>except StopIteration:
>>> raise ValueError('No matching i
Robert Kern wrote:
> Christopher Subich wrote:
>
>
>>Dear Zeus no. Find can be defined as:
>>def find(self, test=lambda x:1):
>>try:
>> item = (s for s in iter(self) if test(s)).next()
>>except StopIteration:
>> raise ValueError('No matching items in list')
>
> I would prefe
Christopher Subich wrote:
> Dear Zeus no. Find can be defined as:
> def find(self, test=lambda x:1):
> try:
>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 retu
Mike Meyer wrote:
> Another thread pointed out a couple of methods that would be nice to
> have on Python collections: find and inject. These are taken from
> http://martinfowler.com/bliki/CollectionClosureMethod.html >.
>
> find can be defined as:
>
> def find(self, test = None):
>
Another thread pointed out a couple of methods that would be nice to
have on Python collections: find and inject. These are taken from
http://martinfowler.com/bliki/CollectionClosureMethod.html >.
find can be defined as:
def find(self, test = None):
for item in self:
if
10 matches
Mail list logo