News for hackers. Stuff that matters.
Re:Origins of Python's “Functional” Features (2009) by tommikaikkonen on Monday January 09, 2017 @01:16AM (#13354398)
Implementing a find function makes this read a lot nicer. You could also call it find_first or find_next.

    def find(predicate, iterable, default=None):
        """Returns the first value that matches predicate, otherwise default=None"""
        return next(
            (x for x in iterable if predicate(x)),
            default
        )
Which turns the expression to

    find(lambda x: 'widgets' in x, mixed_widgets)['widgets']

There are no comments on this comment yet.