Package: influence
Influence - The Python Extender You Asked ForWith influence you can extend python with things like two-dimensionallists, fractions, string subtractors, etc. You can also upgrade pythonwith things it doesn’t have like arrays!OverviewThe influence python library was created with one sole purpose, helpingyou do things that can’t be done in standard python with easeUsageBelow is how to install and use the influence library in your ownprograms!Installation$pipinstallinfluenceor$python3-mpipinstall-UinfluenceThe influence package has two package dependencies, numpy and matplotlib(used for grapher and agrapher classes)CoutCout (common output) has only one class, printer, that helps printtuples, lists, dicts, etc. nicelyImporting:frominfluenceimportcout#orfrominfluence.coutimportPrinterPrinter ClassMethods:Printer.print_list(list)#prints a list nicelyPrinter.print_tuple(tuple)#prints a tuple nicelyPrinter.print_dictionary(dict)#prints a dict nicelyPrinter.print_all(ender,*items)#prints all of items, if ender is False, prints each item on new line#else all items are printed on the same lineCin‘’’Cin (common input), has one class, input, that handles inputspecificallyImporting:frominfluenceimportcin#orfrominfluence.cinimportInputInput ClassMethods:value=Input.input(t,prompt=None)#stores input into value#prompt will be printed, defaults to None#raises ValueError if input does not match type t#raises TypeError if t not able to be casted from inputList2D ClassCreates a 2D list of a square sizeImporting:frominfluence.listimportmultilist#orfrominfluence.list.multilistimportList2DInitializing:l=List2D(rows=1,cols=1)#creates the list to have rows number of rows and cols number of colsMethods:l[r_index][c_index]=item#sets value at r_index and c_index to item#raises IndexError if index out of boundsl[r_index].append(item)#since this is a list, if you wish to append the list#you can do it this way instead of settingsl[r_index][c_index]#returns value at r_index and c_index#raises IndexError if index out of boundsl.print()#prints the listl.remove(r_index,c_index)#removes the value at r_index and c_index#returns true if removed, false if index out of boundsiteminl#returns true if item in l, false otherwisel.index(item)#returns indices of item if found in list#returns [-1] otherwisel.__len__()/len(l)#returns the length of ll.__str__()/str(l)#returns l as a strl.__delitem__(key)/dell[key]#deletes row key from l#raises IndexError if key out of boundsRaggedList ClassCreates a 2D list, but doesn’t need to be of n x n size, inherits fromList2D, and therefore has a dependency toinfluence.extender.list.multilistImporting:frominfluence.listimportragged#orfrominfluence.list.raggedimportRaggedListInitializing:r=RaggedList(rows=1,cols=1)#creates a ragged list starting with rows rows and cols cols#defaults to one for both if no arguments are givenMethods:r.print()#prints the ragged listr.in_bounds(r_index,c_index)#returns true if r_index and c_index are in bounds of the list#returns false otherwiser.set(r_index,c_index,item)#sets value at r_index and c_index to item if in bounds#else extends the ragged list so r_index and c_index are in boundsr.get(r_index,c_index)#returns value at r_index and c_index if in bounds#else returns Noneiteminr#returns true if item is in r, else returns falser.index(item)#returns the indices of item if in r#else returns [-1]r.__len__()/len(r)#returns the length of rAsList ClassUsed to turn strings into lists, duplicate class found in stringsubpackageImporting:frominfluence.listimportaslist#orfrominfluence.list.aslistimportAsListMethods:AsList.character_list(string)#returns string as a list of charactersAsList.word_list(string)#returns string as a list with each word#a word is found when a space is reached in the string#spaces are not included in the listAsList.word_list_with_spaces(string)#same as AsList.word_list(string) except spaces are part of the listAsList ClassUsed to turn strings into lists, duplicate class found in listsubpackageImporting:frominfluence.stringimportaslist#orfrominfluence.string.aslistimportAsListMethods:AsList.character_list(string)#returns string as a list of charactersAsList.word_list(string)#returns string as a list with each word#a word is found when a space is reached in the string#spaces are not included in the listAsList.word_list_with_spaces(string)#same as AsList.word_list(string) except spaces are part of the listSubtract ClassAllows for subtracting of strings, but does not change the input string,instead returns a new stringImporting:frominfluence.stringimportsubtract#orfrominfluence.string.subtractimportSubtractMethods:Subtract.subtract(initial,remove)#removes the first instance of remove from initial#returns a new string#remove can be multiple letters, but must be a stringSubtract.subtract_all(initial,remove)#removes all instances of remove from initial#returns a new string#remove can be multiple letters, but must be a stringConst ClassGives the user access to constants in mathImporting:frominfluence.mathimportconst#orfrominfluence.math.constimportMathConstantsFields:MathConstants.pi#returns the value of piMathConstants.e#returns the value of eMathConstants.tau#returns the value of tauMathConstants.phi#returns the value of phiStats ClassAllows for statistics with int or float datasetsImporting:frominfluence.mathimportstats#orfrominfluence.math.statsimportStatsMethods:Stats.min(dataset)#returns the lowest value in datasetStats.max(dataset)#returns the highest value in datasetStats.range(dataset)#returns the range of the dataset (max - min)Stats.mean(dataset)#returns the mean of the datasetStats.variance(dataset)#returns the variance of the datasetStats.standard_deviation(dataset)#returns the standard deviation of the datasetStats.median(dataset)#returns the median of the datasetStats.mode(dataset)#returns the mode of the dataset as a listCos ClassDoes permutations and combinations equations, inherits from Stats, andtherefore has a dependency to influence.extender.math.statsImporting:frominfluence.mathimportcos#orfrominfluence.math.cosimportCombinatoricsMethods:Combinatorics.factorial(num)#returns the factorial of numCombinatorics.P(n,r)#returns the permutations equation (n! / (n-r)!)Combinatorics.C(n,r)#returns the combinations equation (n! / [(n-r)! * r!])Frac ClassRepresents a fractionImporting:frominfluence.mathimportfrac#orfrominfluence.math.fracimportFractionInitializing:f=Fraction(num,denom)#initializes a fraction to numerator num and denominator denomMethods:f.simplify()#simplifies this fraction, if possiblef.__float__()/float(f)#returns the float value of the fractionf.__int__()/int(f)#returns the int value of the fractionsf.__str__()/str(f)#returns the fraction as a stringf.to_mixed_number(self)#returns f as a mixed numberCompare:f1=Fraction(1,2)f2=Fraction(3,4)#fraction allows forf1<f2f1<=f2f1==f2f1>f2f1>=f2MixedNum ClassRepresents a mixed numberImporting:frominfluence.mathimportmixednum#orfrominfluence.math.mixednumimportMixedNumberInitializing:m=MixedNumber(coeff,num,denom)#creates a mixed number with a coefficient coeff, numerator num#and denominator denomMethods:m.simplify()#simplifies this mixed number, if possiblem.__float__()/float(m)#returns the float value of the mixed numberm.__int__()/int(m)#returns the int value of the mixed numberm.__str__()/str(m)#returns the mixed number as a strm.to_fraction()#returns the mixed number as a new improper fractionCompare:m1=MixedNumber(1,2,3)m2=MixedNumber(4,5,6)#fraction allows form1<m2m1<=m2m1==m2m1>m2m1>=m2Grapher SubpackageAllows for graphing equationsImporting:frominfluence.math.grapherimportEquationfrominfluence.math.grapherimportGraphingErrorfrominfluence.math.grapherimportGrapherEquation Class:Represents an equationInitializing:e=Equation(eq)#eq cannot be inferred#ie 4x+3 needs to be 4*x+3#ie 4x^2+2 needs to be 4*(x**2)+3GraphingError Class:GraphingError.HostileAttackError is thrown when a hostile attack isdetected with eval GraphingError.InstanceError is thrown when graphing,the parameter is not an instance of EquationGrapher Class:Grapher.graph(eq)#graphs eq, if and only if isinstance(eq, Equation) returns TrueAgrapher SubpackageAsynchronous graphing is currently a WIP but are still able to be usedImporting:frominfluence.math.asyncgrapherimportEquationfrominfluence.math.asyncgrapherimportGraphingErrorfrominfluence.math.asyncgrapherimportGrapherAgrapher works in the same exact way except Grapher.graph(eq,timetoclose=None), can have a given timeoutArray ClassMakes an array. An array is like a list, except it has a definite,unchangeable size, but elements can be changed inside of it (unlike atuple)Importing:frominfluence.arrayimportarrays#orfrominfluence.array.arraysimportArrayInitializing:arr=Array(capacity)#initializes the array to its definite lengthMethods:arr[index]#gets the value at indexarr[start:stop:step]#returns a list from an array from a slice of start, stop, and step#raises IndexError if index out of boundsarr[index]=item#sets the value at index to item#raises IndexError if index out of boundsarr.__iter__()/iter(arr)#returns an iterator for the arrayiterator.__next__()/next(iterator)#gets the next element from the iteratorarr.print()#prints the arrayiteminarr#returns true if item is in arr, false otherwisearr.index(item)#returns the index of item if in arr#returns -1 if not foundarr.__len__()/len(arr)#returns the length of arrnotarr#returns True if arr has a capacity of 0arr.__str__()/str(arr)#returns arr as a strarr1+arr2arr1+=arr2#adds the arrays togetherArray2D ClassCreates a 2D Array, inherits from Array, and therefore has a dependencyto influence.upgrader.array.arraysImporting:frominfluence.arrayimportmultiarray#orfrominfluence.array.multiarrayimportArray2DInitializing:arr=Array2D(r,c)#creates a 2D array to a fixed amount of rows (r) and columns (c)Methods:arr[r_index][c_index]#returns the value at r_index and c_index#raises IndexError if index out of boundsarr[r_index][c_index]=item#sets value at r_index and c_index to item#raises IndexError if index out of boundsarr.print()#prints the 2D arrayiteminarr#returns true if item is in arr, false otherwisearr.index(item)#returns the indices of item in arr, if found#returns [-1] otherwisearr.__len__()/len(arr)#returns length of arrStringBuffer ClassMakes strings mutable, like in javaImporting:frominfluence.stringimportstringbuffer#orfrominfluence.string.stringbufferimportStringBufferInitializing:s=StringBuffer(str='')#initializes a string buffer to str, empty if none enteredMethods:s.__len__()/len(s)#returns the length of sobjins#returns true if obj is in s, false otherwises.__iter__()/iter(s)#returns an iterator for ss.__next__()/next(s)#gets next letter in ss.__str__()/str(s)#gets s as a normal strings[index]#gets letter at indexs[start:stop:step]#gets letters starting at start, up to but discluding stop, incrementing by steps[index]=item#sets letter at index to items.append(append)#appends append to ss.index(obj)#returns the index of obj in ss.insert(index,obj)#inserts obj at indexs.replace(start,stop,obj)#replaces the chars from stop to stop (discluding stop) with objdels[index]#deletes the char at indexs1+s2s1+=s2#adds stringbuffers togetherStack ClassRepresents a stack of items, top being the newest, and bottom being theoldestImporting:frominfluence.listimportstack#orfrominfluence.list.stackimportStackInitializing:s=Stack()#creates an empty stackMethods:s.push(obj)#puts an item to the top of the stacks.pop()#removes the top item in the stack#raises stack.EmptyStackError if stack is emptys.peek()#gets the top item in the stack without removing it#returns None if stack is emptys.empty()#returns True if s is emptyobjins#returns True if obj is in s, False otherwises.index(obj)#returns the index of obj, -1 if not founds.__len__()/len(s)#returns the length of ss.__str__()/str(s)#returns s as a strInsertableDict ClassA dict which can insert items at a certain indexImporting:frominfluence.dictimportidict#orfrominfluence.dict.idictimportInsertableDictInitializing:i=InsertableDict()#creates an empty insertable dictMethods:i[key]#gets the value from i of key keyi[key]=item#sets the value at key to item#or creates a new key and value if key not in ii.__len__()/len(i)#gets the length of ii.get(key)#like i[key] but returns None if key is not in ii.append(key,item)#appends key and item to the end of the ii.keys()#returns the keys of ii.values()#returns the values of ii.__str__()/str(i)#returns i as a stri.remove(key)#removes the key and value of keyi.pop()#removes the last element in ii.__iter__()/iter(i)#returns an iter object for ii.__next__()/next(i)#returns the next element in ii.insert(index,key,value)#inserts key and value at index (index starts at 0)TreeSet ClassA normal set (where you can’t have duplicate items), except all itemsare automatically sorted upon addingImporting:frominfluence.setimporttreeset#orfrominfluence.set.treesetimportTreeSetInitializing:ts=TreeSet(t)#creates a treeset that takes in values of type tMethods:ts.add(item)#adds item to ts and sorts the set#raises ValueError if item is not of instance t#returns True if added, False if item already in setobjints#returns True if obj is in ts, False otherwisets.remove(item)#removes item from ts#raises an error if item not in tsts.discard(item)#removes item from ts if found#does not raise an error if not foundts.__len__()/len(ts)#returns the length of tsts.__str__()/str(ts)#returns ts as a strts.__iter__()/iter(ts)#returns an iterator for tsts.__next__()/next(ts)#returns the next element in tsts.pop()#removes the last element in tsTreeMap ClassA normal dictionary, except items are automatically sorted by key fromleast to greatestImporting:frominfluence.dictimporttreemap#orfrominfluence.dict.treemapimportTreeMapInitializing:tm=TreeMap()#initializes an empty treemapMethods:tm.add(key,value)#adds key and value to tm and sorts the dictobjintm#returns True if obj is in tm.keys() or tm.values(), False otherwisetm.keys()#returns the keys in tmtm.values()#returns the values in tmtm.__str__()/str(tm)#returns tm as a strtm.remove(key)#removes the key and value of key from tmtm.pop()#removes the last element key and value from tmtm.__len__()/len(tm)#returns the length of tmtm.__iter__()/iter(tm)#returns an iterator for tmtm.__next__()/next(tm)#returns the next element in tmStemLeaf ClassCreates a stem and leaf plotImporting:frominfluence.mathimportstemandleaf#orfrominfluence.math.stemandleafimportStemLeafInitializing:sl=StemLeaf()#initializes an empty stem and leaf plotMethods:sl.plot(stem,leaf)#adds the stem and leaf to plotsl.remove(stem,leaf)#removes the leaf from the given stem if found#raises stemandleaf.NoStemError if stem not found#raises stemandleaf.NoLeafError if leaf not found in stemsl.__str__()/str(sl)#returns sl as a strsl.empty()#returns True if sl is empty, False otherwiseLicenseMIT LicenseCopyright (c) 2020 RandomKiddoPermission is hereby granted, free of charge, to any person obtaining acopy of this software and associated documentation files (the“Software”), to deal in the Software without restriction, includingwithout limitation the rights to use, copy, modify, merge, publish,distribute, sublicense, and/or sell copies of the Software, and topermit persons to whom the Software is furnished to do so, subject tothe following conditions:The above copyright notice and this permission notice shall be includedin all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESSOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OFMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANYCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THESOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.