Base.countElements

Base.countElements(condition)

The number of values which satisfy the condition.

Parameters:

condition (function, query) –

  • function - accepts an element as its only argument and returns a boolean value to indicate if the element should be counted

  • query - string in the format ‘OPERATOR VALUE’ representing a function (i.e “< 10”, “== yes”, or “is missing”). See nimble.match.QueryString for string requirements.

Returns:

int

Examples

Using a python function.

>>> def greaterThanZero(elem):
...     return elem > 0
>>> X = nimble.identity(5)
>>> numGreaterThanZero = X.countElements(greaterThanZero)
>>> numGreaterThanZero
5

Using a string filter function.

>>> numLessThanOne = X.countElements("<1")
>>> numLessThanOne
20

Keywords: number, counts, tally