proso package

Submodules

proso.dict module

Utility functions for manipulation with Python dictionaries.

proso.dict.group_keys_by_value_lists(d)[source]

Take a dict (A -> [B]( and return another one (B -> [A]). It groups keys from the original dict by their values in lists.

>>> pprint(group_keys_by_value_lists({1: [True], 2: [False], 3: [True], 4: [True, False]}))
{False: [2, 4], True: [1, 3, 4]}
Parameters:d (dict) – original dictionary which will be transformed.
Returns:new keys are taken from original values, each new key points to a list where all values are original keys pointing to the same value
Return type:dict
proso.dict.group_keys_by_values(d)[source]

Take a dict (A -> B( and return another one (B -> [A]). It groups keys from the original dict by their values.

>>> pprint(group_keys_by_values({1: True, 2: False, 3: True, 4: True}))
{False: [2], True: [1, 3, 4]}
Parameters:d (dict) – original dictionary which will be transformed.
Returns:new keys are taken from original values, each new key points to a list where all values are original keys pointing to the same value
Return type:dict

proso.func module

proso.func.LAMBDA()
proso.func.fixed_point(is_zero, plus, minus, f, x)[source]

Get the least fixed point when it can be computed piecewise.

>>> sorted(fixed_point(
...    is_zero=lambda xs: len(xs) == 0,
...    plus=lambda xs, ys: xs + ys,
...    minus=lambda xs, ys: [x for x in xs if x not in ys],
...    f=lambda xs: [x + 1 for x in xs if x < 10],
...    x=[0, 5, 8]
... ))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Parameters:
  • is_zero – function returning True if the given value is zero
  • plus – function taking two values and returning their addition
  • minus – function taking two values and returning ther difference
  • f – function computing the expected value
  • x – initial value
Returns:

The least fixed point.

proso.func.function_name(function)[source]
proso.func.is_lambda(fun)[source]

Check whether the given function is a lambda function.

def not_lambda_fun():
    return 1

lambda_fun = lambda: 1

print(
    is_lambda(not_lambda_fun),
    is_lambda(lambda_fun)
)
False True
Parameters:fun (function) –
Returns:True if the given function is a lambda function, False otherwise
Return type:bool
proso.func.memo_Y(f)[source]

Memoized Y combinator.

@memo_Y
def fib(f):
    def inner_fib(n):
        if n > 1:
            return f(n - 1) + f(n - 2)
        else:
            return n
    return inner_fib

print(fib(100))
354224848179261915075

proso.list module

Utility functions for manipulation with Python lists.

proso.list.flatten(xxs)[source]

Take a list of lists and return list of values.

>>> flatten([[1, 2], [3, 4]])
[1, 2, 3, 4]
proso.list.group_by(what, by)[source]

Take a list and apply the given function on each its value, then group the values by the function results.

>>> group_by([i for i in range(10)], by=lambda x: x % 2 == 0)
{False: [1, 3, 5, 7, 9], True: [0, 2, 4, 6, 8]}
Parameters:
  • what – a list which will be transformed
  • by – a function which will be applied on values of the given list
Returns:

values groupped by the function results

Return type:

dict

proso.rand module

proso.rand.random_string(n)[source]
proso.rand.roulette(weights, n)[source]

Choose randomly the given number of items. The probability the item is chosen is proportionate to its weight.

print(roulette({'cat': 2, 'dog': 1000}, 1))
['dog']
Parameters:
  • weights (dict) – item -> weight mapping, non-positive weights are forbidden
  • n (int) – number of chosen items
Returns:

randomly chosen items

Return type:

list

proso.reflection module

proso.reflection.instantiate(classname, *args, **kwargs)[source]

Take a classname and instantiate it.

>>> instantiate('collections.defaultdict')
defaultdict(None, {})

proso.release module

proso.svg module

class proso.svg.Printer[source]

Bases: object

print_circle(x, y, r, color=0, width=1, border_color=0)[source]
print_line(x1, y1, x2, y2, color=0, width=1)[source]
print_output(output)[source]
print_square(x, y, a, color=0, width=1, border_color=0)[source]
print_text(x, y, text, color=0, font_size=12)[source]
to_file(filename)[source]

proso.time module

class proso.time.timeit(name=None)[source]

Bases: object

proso.time.timer(name)[source]

Module contents