Overloaded version of the built-in python classes: list and set to include some extra functionalities.
Project description
Overloaded Iterables
Overloaded versions of the built-in python classes: <list>
and <set>
, to include some extra functionalities as an experiment.
An experimental Python package to extend the methods found in Python's built-in list and set classes to add some extra functionality that I, personally find useful in my day-to-day implementations and was too lazy to keep writing/copy-pasting again and again.
Specifications
-
Python Version:
Python v3.8+
-
Code Coverage:
Python Package Index
Installation
python -m pip install overloaded-iterables
Classes
The current iteration contains the following classes
1. OverloadedList
- A non-datatype constrained, single-dimensional collection of values.
- Inherits solely from Python's built-in
<list>
class.
from overloaded_iterables.classes import OverloadedList
obj = OverloadedList(*args)
2. OverloadedSet
- A non-datatype constrained, single-dimensional collection of unique values.
- Inherits solely from Python's built-in
<set>
class.
from overloaded_iterables.classes import OverloadedSet
obj = OverloadedSet(*args)
Functions and Methods
-
<class>.mean()
-
Find the mean of the values in the given iterable class object.
-
Arguments:
self
-
Returns:
float (64-bit)
-
Example:
_mean: float = obj.mean()
-
-
<class>.sum()
-
Claculate the sum of all the elements in the given iterable class object.
-
Arguments:
self
-
Returns:
float (64-bit)
-
Example:
_sum: float = obj.sum()
-
-
<class>.prod()
-
Calculate the product of all the elements in the given iterable class object.
-
Arguments:
self
-
Returns:
float (64-bit)
-
Example:
_product: float = obj.prod()
-
-
<class>.sort()
-
Sorts the contents of the given iterable class object via the Timsort sorting algorithm.
-
Arguments:
self
,key: None | default: None
,reverse: bool | default: False
-
Returns
object: <list>
-
Example:
sorted_seq: list = obj.sort()
-
-
<class>.raise_to()
-
Raises each element in the iterable class object to the given power.
-
Arguments:
self
,power: float (64-bit) | default: 1.0
-
Returns
object: <class>
-
Example:
import numpy as np from secrets import choice ## Taking the power variable, 'z' to be a random integer between -10 and +10 z:float = choice([i for i in np.arange(-10, 10, 0.5)]) _raised_sequence: type(obj) = obj.raise_to(power=z)
-
-
<class>.rms()
-
Finds the Root-Mean-Square (RMS) of the values in the current iterable class object.
-
Arguments:
self
,power: float | default: 2
,root: int | default: 2
-
Returns:
float (64-bit)
-
Example:
_rms: float = obj.rms()
-
-
<class>.median()
-
Finds the median of the contents of the given iterable class object.
-
Arguments:
self
-
Returns:
float (64-bit)
-
Example:
_median:float = obj.median()
-
-
<class>.hist()
(OverloadedList only)-
Plots the histogram of the frequency distribution of the elements in the OverloadedList.
-
Arguments:
self
,bins: int | default: 10
,title: str | default: 'Histogram'
,x_label: str | default: 'Values --->'
,y_label: str | default: 'Frequencies --->'
,save_dir: str | default: None
,file_name: str | default: None
,histtype: str | default: 'step'
,align: str | default: 'mid'
,orientation: str | default: 'vertical'
,log_scale: bool | default: False
,show: bool | default: False
-
Process:
- Shows the generated figure if
show
is set toTrue
- Saves the generated figure if
save_dir
is provided.
- Shows the generated figure if
-
Returns:
bool
-
Example:
fig_check:bool = obj.hist(show=True, save_dir='figures', file_name='some-figure')
-
-
<class>.plot()
(OverloadedList only)-
Plots the lineplot of the frequency distribution of the elements in the OverloadedList.
-
Arguments:
self
,title: str | default: 'Line Plot'
,x_label: str | default: 'Values --->'
,y_label: str | default: 'Frequencies --->'
,save_dir: str | default: None
,file_name: str | default: None
,color: str | default: '#000000'
,linewidth: float | default: 1
,marker: str | default: ','
,markerfacecolor: str | default: '#252525'
,marker_size: float | default: 1.0
,show: bool | default: False
-
Process:
- Shows the generated figure if
show
is set toTrue
- Saves the generated figure if
save_dir
is provided.
- Shows the generated figure if
-
Returns:
bool
-
Example:
fig_check:bool = obj.plot(show=True, save_dir='figures', file_name='some-figure')
-
-
<class>.scatter()
(OverloadedList only)-
Plots the scatterplot of the frequency distribution of the elements in the OverloadedList.
-
Arguments:
self
,title: str | default: 'Scatter Plot'
,x_label: str | default: 'Values --->'
,y_label: str | default: 'Frequencies --->'
,save_dir: str | default: None
,file_name: str | default: None
,size: List[float] | default: [1.25]
,color: str | default: '#000000'
,marker: str | default: ','
,line_width: float | default: 2
,show: bool | default: False
-
Process:
- Shows the generated figure if
show
is set toTrue
- Saves the generated figure if
save_dir
is provided.
- Shows the generated figure if
-
Returns:
bool
-
Example:
fig_check:bool = obj.scatter(show=True, save_dir='figures', file_name='some-figure')
-
-
<class>.len (property)
-
Finds and returns the length of the current iterable class object as a property.
-
Arguments:
self
-
Returns:
int
-
Example:
_l: int = obj.len
-
-
<class>.frequencies (property)
(OverloadedList only)-
Finds the frequencies of all elements of the given
OverloadedList
class and returns a list of unique values with their discovered frequencies. -
Arguments:
self
-
Returns:
OverloadedList, OverloadedList
-
Example:
values: Overloadedlist, frequencies: OverloadedList = obj.frequencies
-
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
Hashes for overloaded-iterables-0.6.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 936ce4f69ee544c9fa3be56a0a6b769a42297ee27aeb3050aa7674a1a6a5f21c |
|
MD5 | 12eb5524d3d2781f18b4779591aca52d |
|
BLAKE2b-256 | 40a4196a0ed707ab80cc29741fbc55b8e85cd5ecf1ff700cf04771b4a45fa00d |