<commit_before>from __future__ import absolute_import
import logging

import civis
from civis.compat import lru_cache
from civis.resources import generate_classes_maybe_cached
from civis._utils import get_api_key


log = logging.getLogger(__name__)

RETRY_CODES = [429, 502, 503, 504]


def find(object_list, filter_func=None, **kwargs):
    """Return the objects from ``object_list`` that satisfy the filters.

    Parameters
    ----------
    object_list : iterable
        An iterable of arbitrary objects, particularly dicts and objects with
        attributes that can be targeted by the filters in ``kwargs``.
    filter_func : callable, optional
        A one-argument function. If specified, ``kwargs`` are ignored.
        An ``object`` from the input iterable is kept in the returned list
        if and only if ``bool(filter_func(object))`` is ``True``.
    **kwargs
        Key-value pairs for more fine-grained filtering; they cannot be used
        in conjunction with ``filter_func``. All keys must be strings.
        An ``object`` from the input iterable is kept in the returned
        list, unless one of the following conditions is met:
        - ``key`` is not an attribute of ``object``
        - ``value`` is a one-argument function and
          ``bool(value(object.key))`` is ``False``
        - ``value`` is ``False``
        - ``object.key`` is not equal to ``value``

    Returns
    -------
    list

    Examples
    --------
    >>> import civis
    >>> client = civis.APIClient()
    >>> # creds is a list of dicts representing credentials
    >>> creds = client.credentials.list()
    >>> # target_creds contains dicts with the key-value ('name', 'username')
    >>> target_creds = find(creds, name='username')

    See Also<commit_msg>DOC Use dict syntax as the more common use case<commit_after>from __future__ import absolute_import
import logging

import civis
from civis.compat import lru_cache
from civis.resources import generate_classes_maybe_cached
from civis._utils import get_api_key


log = logging.getLogger(__name__)

RETRY_CODES = [429, 502, 503, 504]


def find(object_list, filter_func=None, **kwargs):
    """Return the objects from ``object_list`` that satisfy the filters.

    Parameters
    ----------
    object_list : iterable
        An iterable of arbitrary objects, particularly dicts and objects with
        attributes that can be targeted by the filters in ``kwargs``.
    filter_func : callable, optional
        A one-argument function. If specified, ``kwargs`` are ignored.
        An ``object`` from the input iterable is kept in the returned list
        if and only if ``bool(filter_func(object))`` is ``True``.
    **kwargs
        Key-value pairs for more fine-grained filtering; they cannot be used
        in conjunction with ``filter_func``. All keys must be strings.
        An ``object`` from the input iterable is kept in the returned
        list, unless one of the following conditions is met:
        - ``key`` is not an attribute of ``object``
        - ``value`` is a one-argument function and
          ``bool(value(object[key]))`` is ``False``
        - ``value`` is ``False``
        - ``object[key]`` is not equal to ``value``

    Returns
    -------
    list

    Examples
    --------
    >>> import civis
    >>> client = civis.APIClient()
    >>> # creds is a list of dicts representing credentials
    >>> creds = client.credentials.list()
    >>> # target_creds contains dicts with the key-value ('name', 'username')
    >>> target_creds = find(creds, name='username')

    See Also
{'fraction_non_alphanumeric': 0.11185682326621924, 'fraction_numerical': 0.006711409395973154, 'mean_word_length': 2.896514161220044, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5165800', 'n_tokens_mistral': 992, 'n_tokens_neox': 958, 'n_words': 386}