Exemplo n.º 1
0
def average(collection, callback=None):
    """Calculate arithmetic mean of each element in `collection`. If callback
    is passed, each element of `collection` is passed through a callback before
    the mean is computed.

    Args:
        collection (list|dict): Collection to process.
        callback (mixed, optional): Callback applied per iteration.

    Returns:
        float: Result of mean.

    Example:

        >>> average([1, 2, 3, 4])
        2.5
        >>> average([1, 2, 3, 4], lambda x: x ** 2)
        7.5

    See Also:
        - :func:`average` (main definition)
        - :func:`avg` (alias)
        - :func:`mean` (alias)

    .. versionadded:: 2.1.0
    """
    return add(collection, callback) / pyd.size(collection)
Exemplo n.º 2
0
def average(collection, callback=None):
    """Calculate arithmetic mean of each element in `collection`. If callback
    is passed, each element of `collection` is passed through a callback before
    the mean is computed.

    Args:
        collection (list|dict): Collection to process.
        callback (mixed, optional): Callback applied per iteration.

    Returns:
        float: Result of mean.

    Example:

        >>> average([1, 2, 3, 4])
        2.5
        >>> average([1, 2, 3, 4], lambda x: x ** 2)
        7.5

    See Also:
        - :func:`average` (main definition)
        - :func:`avg` (alias)
        - :func:`mean` (alias)

    .. versionadded:: 2.1.0
    """
    return add(collection, callback) / pyd.size(collection)
Exemplo n.º 3
0
def mean_by(collection, iteratee=None):
    """Calculate arithmetic mean of each element in `collection`. If iteratee
    is passed, each element of `collection` is passed through a iteratee before
    the mean is computed.

    Args:
        collection (list|dict): Collection to process.
        iteratee (mixed, optional): Iteratee applied per iteration.

    Returns:
        float: Result of mean.

    Example:

        >>> mean_by([1, 2, 3, 4], lambda x: x ** 2)
        7.5

    .. versionadded:: 4.0.0
    """
    return sum_by(collection, iteratee) / pyd.size(collection)
Exemplo n.º 4
0
def test_size(case):
    assert _.size(case) == len(case)
Exemplo n.º 5
0
 def __len__(self):
     return _.size(self.storage)