def first(seq, key=(lambda x: bool(x)), default=None, apply=(lambda x: x)):
    "Give the first value that satisfies the key test.\n\n    Args:\n        seq (iterable):\n        key (callable): test for each element of iterable\n        default: returned when all elements fail test\n        apply (callable): applied to element before return, but not to default value\n\n    Returns: first element in seq that passes key, mutated with optional apply\n\n    Examples:\n        >>> first([0, False, None, [], (), 42])\n        42\n        >>> first([0, False, None, [], ()]) is None\n        True\n        >>> first([0, False, None, [], ()], default='ohai')\n        'ohai'\n        >>> import re\n        >>> m = first(re.match(regex, 'abc') for regex in ['b.*', 'a(.*)'])\n        >>> m.group(1)\n        'bc'\n\n        The optional `key` argument specifies a one-argument predicate function\n        like that used for `filter()`.  The `key` argument, if supplied, must be\n        in keyword form.  For example:\n        >>> first([1, 1, 3, 4, 5], key=lambda x: x % 2 == 0)\n        4\n\n    "
    return next((apply(x) for x in seq if key(x)), (default() if callable(default) else default))
Give the first value that satisfies the key test.

Args:
    seq (iterable):
    key (callable): test for each element of iterable
    default: returned when all elements fail test
    apply (callable): applied to element before return, but not to default value

Returns: first element in seq that passes key, mutated with optional apply

Examples:
    >>> first([0, False, None, [], (), 42])
    42
    >>> first([0, False, None, [], ()]) is None
    True
    >>> first([0, False, None, [], ()], default='ohai')
    'ohai'
    >>> import re
    >>> m = first(re.match(regex, 'abc') for regex in ['b.*', 'a(.*)'])
    >>> m.group(1)
    'bc'

    The optional `key` argument specifies a one-argument predicate function
    like that used for `filter()`.  The `key` argument, if supplied, must be
    in keyword form.  For example:
    >>> first([1, 1, 3, 4, 5], key=lambda x: x % 2 == 0)
    4
def first(seq, key=(lambda x: bool(x)), default=None, apply=(lambda x: x)):
    "Give the first value that satisfies the key test.\n\n    Args:\n        seq (iterable):\n        key (callable): test for each element of iterable\n        default: returned when all elements fail test\n        apply (callable): applied to element before return, but not to default value\n\n    Returns: first element in seq that passes key, mutated with optional apply\n\n    Examples:\n        >>> first([0, False, None, [], (), 42])\n        42\n        >>> first([0, False, None, [], ()]) is None\n        True\n        >>> first([0, False, None, [], ()], default='ohai')\n        'ohai'\n        >>> import re\n        >>> m = first(re.match(regex, 'abc') for regex in ['b.*', 'a(.*)'])\n        >>> m.group(1)\n        'bc'\n\n        The optional `key` argument specifies a one-argument predicate function\n        like that used for `filter()`.  The `key` argument, if supplied, must be\n        in keyword form.  For example:\n        >>> first([1, 1, 3, 4, 5], key=lambda x: x % 2 == 0)\n        4\n\n    "
    return next((apply(x) for x in seq if key(x)), (default() if callable(default) else default))