smpl.util

Simplified general utilities.

find_nearest(array, value)

Return the element in array closest to value

find_nearest_index(array, value)

Returns the index of the element in array closest to value

get(key, ddict, default)

Returns dict[key] if this exists else default.

has(key, ddict)

Checks if the key is in the dict and not None.

times(s, n)

Concats string s n times.

true(key, ddict)

Checks if the key is in the dict and not None and True.

Functions

smpl.util.find_nearest(array, value)[source]

Return the element in array closest to value

Examples

>>> find_nearest([1,7,6,2] , 1.9)
2
smpl.util.find_nearest_index(array, value)[source]

Returns the index of the element in array closest to value

Examples

>>> find_nearest_index([1,7,6,2] , 1.9)
3
smpl.util.get(key, ddict, default)[source]

Returns dict[key] if this exists else default.

Examples

>>> d = {'a' : 1 , 'b' : 2 , 'c' : 3}
>>> get('a',d,5)
1
>>> get('x',d,5)
5
smpl.util.has(key, ddict)[source]

Checks if the key is in the dict and not None.

Examples

>>> d = {'a' : 1 , 'b' : 2 , 'c' : 3}
>>> has('a',d)
True
>>> has('x',d)
False
smpl.util.times(s, n)[source]

Concats string s n times.

Examples

>>> times("hi",5)
'hihihihihi'
smpl.util.true(key, ddict)[source]

Checks if the key is in the dict and not None and True.

Examples

>>> d = {'a' : True , 'b' : True , 'c' : False}
>>> true('a', d)
True
>>> true('c', d)
False
>>> true('x', d)
False