understreck package

Submodules

understreck.chunks module

understreck.chunks.calculate_size(to_chunk, num_chunks)[source]

Calculate the max chunk size for each new chunk of a list.

Arguments:
to_chunk {list} – [description] num_chunks {int} – [description]
Returns:
int – The max size for each chunk
understreck.chunks.split(to_chunk, num_chunks)[source]

split a list into evenly sized chunks

Args:
to_chunk: The original list to turn in to chunks num_chunks: The total number of chunks to create

Returns: A new list with the

understreck.exceptions module

exception understreck.exceptions.InvalidArgumentError[source]

Bases: exceptions.Exception

understreck.filter module

understreck.filter.filter(to_filter, filter_to_apply)[source]

Filters a list or tuple

Examples:
users = [
{“user”: “barney”, “age”: 36, “active”: True}, {“user”: “fred”, “age”: 40, “active”: False},

]

# Using a lambda function result = _.filter(users, lambda x: not x.get(“active”)) result == [{“user”: “fred”, “age”: 40, “active”: False}]

# Using partial dictionary result = _.filter(users, {“age”: 36, “active”: True}) result == [{“user”: “barney”, “age”: 36, “active”: True}]

# Using a list with a property name and value result = _.filter(users, [“active”, False]) result == [{“user”: “fred”, “age”: 40, “active”: False}]

# Using a list with a property name. The value must be truthy. result = _.filter(users, [“active”]) result == [{“user”: “barney”, “age”: 36, “active”: True}]

Parameters:
  • to_filter – the tuple or list to filter
  • filter_to_apply – A function or list that defies the filter
Returns:

A filtered list or tuple with the same type as to_filter

understreck.nested_get module

understreck.nested_get.get(input_dict, nested_key)

Get a subkey from a dict

This will return a subkey from a dictionary. It solves a problem when having to perform safe get on nested dictionaries.

Arguments:

input_dict {dict} – The dictionary to perform the get on nested_key {str, list, tuple} – The key can be or dot delimited string

or list/tuple.
Returns:
Object or None – The value of the key or None
understreck.nested_get.nested_get(input_dict, nested_key)[source]

Get a subkey from a dict

This will return a subkey from a dictionary. It solves a problem when having to perform safe get on nested dictionaries.

Arguments:

input_dict {dict} – The dictionary to perform the get on nested_key {str, list, tuple} – The key can be or dot delimited string

or list/tuple.
Returns:
Object or None – The value of the key or None

understreck.strip module

understreck.strip.strip(text)[source]

Remove indents from multi-line strings

Example:

to_strip = ‘’’This is a multi-line string’’’

strip(to_strip) == “This is a

multi-line string”

param text:The string to strip indents from
return:A string with the indents removed

Module contents

Top-level package for Understreck.