A package for Python utility functions.
Project description
About
BumBag is a collection of Python utility functions:
Installation
bumbag
is available on PyPI for Python 3.8+:
pip install bumbag
Examples
Measure elapsed wall-clock time and compute total elapsed time with stopwatch
:
>>> import bumbag
>>> import time
>>> with bumbag.stopwatch(1) as sw1:
... time.sleep(1)
...
2023-01-01 12:00:00 -> 2023-01-01 12:00:01 = 1.00124s - 1
>>> with bumbag.stopwatch(2) as sw2:
... time.sleep(1)
...
2023-01-01 12:01:00 -> 2023-01-01 12:01:01 = 1.00168s - 2
>>> sw1 + sw2
2.00291s - total elapsed time
Easily flatten
an irregular list:
>>> import bumbag
>>> irregular_list = [
... ["one", 2],
... 3,
... [(4, "five")],
... [[["six"]]],
... "seven",
... [],
... ]
>>> list(bumbag.flatten(irregular_list, 8, [9, ("ten",)]))
['one', 2, 3, 4, 'five', 'six', 'seven', 8, 9, 'ten']
Use highlight_string_differences
to see differences between two strings easily:
>>> import bumbag
>>> print(bumbag.highlight_string_differences("hello", "hall"))
hello
| |
hall
Quickly compare two Python sets with two_set_summary
:
>>> import bumbag
>>> x = {"a", "c", "b", "g", "h"}
>>> y = {"c", "d", "e", "f", "g"}
>>> summary = bumbag.two_set_summary(x, y)
>>> print(summary["report"])
x (n=5): {'a', 'b', 'c', ...}
y (n=5): {'c', 'd', 'e', ...}
x | y (n=8): {'a', 'b', 'c', ...}
x & y (n=2): {'c', 'g'}
x - y (n=3): {'a', 'b', 'h'}
y - x (n=3): {'d', 'e', 'f'}
x ^ y (n=6): {'a', 'b', 'd', ...}
jaccard = 0.25
overlap = 0.4
dice = 0.4
disjoint?: False
x == y: False
x <= y: False
x < y: False
y <= x: False
y < x: False
Contributing to BumBag
Your contribution is greatly appreciated! See the following links to help you get started:
License
bumbag
was created by the BumBag Developers.
It is licensed under the terms of the BSD 3-Clause license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
bumbag-5.2.1.tar.gz
(19.0 kB
view hashes)
Built Distribution
bumbag-5.2.1-py3-none-any.whl
(21.2 kB
view hashes)