Package: overloaded-iterables
Overloaded IterablesOverloaded 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.Python Package IndexProject HomepageContentsInstallationpython-mpipinstalloverloaded-iterablesClassesThe current iteration contains the following classes1. OverloadedListA non-datatype constrained, single-dimensional collection of values.Inherits solely from Python's built-in<list>class.fromoverloaded_iterables.classesimportOverloadedListobj=OverloadedList(*args)2. QueueA non-datatype constrained, single-dimensional collection of values that follows thefirst-in-first-out(FiFo)principle for insertions and deletion i.e, insertions will be made to the end of the sequence while deletions will be made to the beginning of the sequence.Inherits solely from the<OverloadedList>class.fromoverloaded_iterables.classesimportQueueobj=Queue(*args)3. StackA non-datatype constrained, single-dimensional collection of values that follows thefirst-in-last-out(FiLo)principle for insertions and deletion i.e, insertions and deletions, both will be made to the end of the sequence.Inherits solely from the<OverloadedList>class.fromoverloaded_iterables.classesimportStackobj=Stack(*args)4. OverloadedSetA non-datatype constrained, single-dimensional collection ofuniquevalues.Inherits solely from Python's built-in<set>class.fromoverloaded_iterables.classesimportOverloadedSetobj=OverloadedSet(*args)Functions and MethodsThe functions, methods and properties are categorised into two segments: for the base classes (OverloadedListandOverloadedSet) and for the
inheriting classes (QueueandStack)OverloadedList and OverloadedSetThe following are the functions, methods and properties belonging to the base classes.OverloadedListbeing a daughter of the<list>class, inherits all of its associated methods and properties as well, such asappend(),extend(),count(),et cetera.OverloadedSetbeing a daughter of the<set>class, inherits all of its associated methods and properties as well, such asadd(),clear(),difference(),et cetera.<class>.mean()Find themeanof the values in the given iterable class object.Arguments:selfReturns:float (64-bit)Example:_mean:float=obj.mean()<class>.sum()Claculate the sum of all the elements in the given iterable class object.Arguments:selfReturns:float (64-bit)Example:_sum:float=obj.sum()<class>.prod()Calculate the product of all the elements in the given iterable class object.Arguments:selfReturns:float (64-bit)Example:_product:float=obj.prod()<class>.sort()Sorts the contents of the given iterable class object via theTimsortsorting algorithm.Arguments:self,key: None | default: None,reverse: bool | default: FalseReturnsobject: <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.0Returnsobject: <class>Example:importnumpyasnpfromsecretsimportchoice## Taking the power variable, 'z' to be a random integer between -10 and +10z:float=choice([iforiinnp.arange(-10,10,0.5)])_raised_sequence:type(obj)=obj.raise_to(power=z)<class>.rms()Finds theRoot-Mean-Square (RMS)of the values in the current iterable class object.Arguments:self,power: float | default: 2,root: int | default: 2Returns:float (64-bit)Example:_rms:float=obj.rms()<class>.median()Finds themedianof the contents of the given iterable class object.Arguments:selfReturns:float (64-bit)Example:_median:float=obj.median()<class>.hist()(OverloadedList only)Plots thehistogramof 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: FalseProcess:Shows the generated figure ifshowis set toTrueSaves the generated figure ifsave_diris provided.Returns:boolExample:fig_check:bool=obj.hist(show=True,save_dir='figures',file_name='some-figure')<class>.plot()(OverloadedList only)Plots thelineplotof 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: FalseProcess:Shows the generated figure ifshowis set toTrueSaves the generated figure ifsave_diris provided.Returns:boolExample:fig_check:bool=obj.plot(show=True,save_dir='figures',file_name='some-figure')<class>.scatter()(OverloadedList only)Plots thescatterplotof 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: FalseProcess:Shows the generated figure ifshowis set toTrueSaves the generated figure ifsave_diris provided.Returns:boolExample: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:selfReturns:intExample:_l:int=obj.len<class>.frequencies (property)(OverloadedList only)Finds the frequencies of all elements of the givenOverloadedListclass and returns a list of unique values with their discovered frequencies.Arguments:selfReturns:OverloadedList, OverloadedListExample:values:Overloadedlist,frequencies:OverloadedList=obj.frequenciesQueue and StackThe following are the functions, methods and properties belonging to the inheriting (daughter) classes.QueueandStackbeing daughters of theOverloadedListclass, inherit all of its associated methods and properties as well, such asmean(),rms(),frequencies,et cetera.<class>.insert()Insertsvaluetowards the end of the object.Arguments:self,value: anyReturns:None(is an in-place method)Example:queue=Queue(*args)stack=Stavk(*args)queue.insert(value=value)stack.insert(value=value)<class>.pop()Deletesnumelements from the beginning of the object in case ofQueueand from the end of the object in case ofStack.Arguments:self,num: int | default: 1Returns:None(is an in-place method)Example:queue=Queue(*args)stack=Stack(*args)queue.pop(num=num)stack.pop(num=num)Development Setupgit clone https://<personal-access-token>@github.com/Arkiralor/overloaded_iterables.gitcd overloaded_aiterablespython -m venv envsource env/bin/activatesource env/Scripts/activatefor Windows.chmod +x scripts/*sh scripts/install.shto install all dependencies.sh scripts/uninstall.shto uninstall all dependencies (can be very useful if you forgot to activate thevirtualEnvironmentbefore runninginstall.sh).sh scripts/generate_coverage_report&&sh scripts/run_tests.shto make sure everything is working as intended.ContributionIf you choose to contribute to this package by addressing any of the issues or tickets listed, kindly follow the following workflow.Assign yourself or ask an administrator to assign yourself to the issue.Clone/fork the codebase and setup the development environment as shown above.Checkout to your own branch, which should ideally be named what the ticket number is in a url-safe format i.e, if the ticket name isWEB_003, then the branch name will beweb-003.git push --set-upstream origin <branchName>to pre-create the necessary branch on github.Make the required changes to the correct files in thesrcdirectory.Add any testCases required to the correct module/file/class in thetestsdirectory.sh scripts/run_tests.shto make sure no breaking changes were made.MAKE SURE ALL TESTS PASS BEFORE PROCEEDING TO THE NEXT STEP(S)Add and commit your changes to your branch with a relevant commit message.git merge origin/masterto pull from the master branch to your branch.sh scripts/run_tests.shagain to make sure nothing was broken by the merge.MAKE SURE ALL TESTS PASS BEFORE PROCEEDING TO THE NEXT STEP(S)git pushto push the changes to the remote branch.Create a Pull Request from your remote branch tomaster.If any code changes were requested, execute them as requested and restart from step #6.