API Reference

sugar.arrays.average(array)[source]

Returns the average for all the values in the given array.

Parameters:array (list) – List of values.
Returns:Average of all the values in the given list.
Return type:int/float

Example

>>> float(average([1, 2, 3]))
2.0

New in version 0.1.0.

sugar.arrays.construct(var, callback)[source]

Constructs an array of var length from the values of callback.

Parameters:
  • var (int) – Length of the array intended.
  • callback – A method that can take in each variable from the given range and return back a new value based on the method definition.
Returns:

A list of callback values.

Return type:

list

Example

>>> construct(4, lambda x: x * 2)
[0, 2, 4, 6]

New in version 0.1.0.

sugar.arrays.count(array, value)[source]

Counts all elements in the array that match the given value.

Parameters:
  • array (list) – A list of values provided by the user to search for.
  • value (int/float/str) – Value that needs to be counted.
Returns:

Count of the given value.

Return type:

int

Example

>>> count([1, 2, 3, 3], 3)
2

New in version 0.1.0.

sugar.arrays.subtract(array, item)[source]

Subtracts item from the array and returns the result as a new array. If item is also an array, all elements in it will be removed.

Parameters:
  • array (list) – A list of values provided by the user.
  • item (list/int/float/str) – A value that needs to be removed from array.
Returns:

A new list with the item removed.

Return type:

list

Example

>>> subtract([1, 2, 3], 2)
[1, 3]
>>> subtract ([1, 2, 3], [1, 3])
[2]
>>> subtract([1, 2, 3], 4)
[1, 2, 3]

New in version 0.1.0.