Skip to main content

Python library of useful but lonely functions and classes

Project description

Slytherin

Slytherin is a collection of useful but lonely functions and classes that don't belong to other libraries.

Installation

pip install slytherin

Usage

collections

cross_lists()

from slytherin.collections import cross_lists
list1 = [1, 2, 3]
list2 = [4, 5]
list3 = [[6, 7], [8, 9]]

cross_lists(list1, list2, list3)

outputs:

[(1, 4, [6, 7]),
 (1, 4, [8, 9]),
 (1, 5, [6, 7]),
 (1, 5, [8, 9]),
 (2, 4, [6, 7]),
 (2, 4, [8, 9]),
 (2, 5, [6, 7]),
 (2, 5, [8, 9]),
 (3, 4, [6, 7]),
 (3, 4, [8, 9]),
 (3, 5, [6, 7]),
 (3, 5, [8, 9])]
cross_lists([list1, list2, list3])

also outputs:

[(1, 4, [6, 7]),
 (1, 4, [8, 9]),
 (1, 5, [6, 7]),
 (1, 5, [8, 9]),
 (2, 4, [6, 7]),
 (2, 4, [8, 9]),
 (2, 5, [6, 7]),
 (2, 5, [8, 9]),
 (3, 4, [6, 7]),
 (3, 4, [8, 9]),
 (3, 5, [6, 7]),
 (3, 5, [8, 9])]

get_size(obj)

The get_size() method calculates the memory footprint of a Python object recursively.

The exclude_objects argument is a list of objects and is optional with the default value of None. Any object in the exclude_objects list will be excluded from the recursive search. It can be used to avoid double counting the size when objects point to each other.

from slytherin import get_size
get_size(obj=[1,2,3], exclude_objects=None)

import pandas as pd
get_size(obj=pd.DataFrame({'id': range(1000), 'name':['Godric', 'Helga', 'Rowena', 'Salazar']*250}))

colour(text, text_colour, style, background_colour)

The colour() method can be used to add colour to printing text.

The colour are integers from 0 to 7:

  • black: 0
  • red: 1
  • green: 2
  • yellow: 3
  • blue: 4
  • purple: 5
  • cyan: 6
  • white: 7

The style argument is an integer between 0 and 5:

  • normal: 0
  • bold: 1
  • underline: 2
  • negative1: 3
  • negative2: 5
from slytherin import colour
print(colour(text='Hello world!', text_colour=4))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

slytherin-2020.9.18.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

slytherin-2020.9.18-py3-none-any.whl (23.5 kB view details)

Uploaded Python 3

File details

Details for the file slytherin-2020.9.18.tar.gz.

File metadata

  • Download URL: slytherin-2020.9.18.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0.post20200210 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for slytherin-2020.9.18.tar.gz
Algorithm Hash digest
SHA256 eb31116f86fdfb8b9ecd3d297183d6585b7bb1ce9aaa4bc7a686a1f981147c5f
MD5 39774bd287b1d59167c480fe01c31721
BLAKE2b-256 7c2d4e78d52346502f6bf500ec92842e122e577e05a358051c56797613102fe5

See more details on using hashes here.

File details

Details for the file slytherin-2020.9.18-py3-none-any.whl.

File metadata

  • Download URL: slytherin-2020.9.18-py3-none-any.whl
  • Upload date:
  • Size: 23.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0.post20200210 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for slytherin-2020.9.18-py3-none-any.whl
Algorithm Hash digest
SHA256 0e40feeb41751323d989a3e5433fd522ef9ef491d24dd81c044f0dfbad421541
MD5 eeabe9e2ed140848a47c358fae7a7549
BLAKE2b-256 914d70b7b931966c9ea3ce15732dc805aa8c605afcc775364864d6a91cbc79b4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page