{ "info": { "author": "MisterL2", "author_email": "misterl2@gmx.net", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6" ], "description": "# python-util\n\n## General\n\n\n### Functional Programming\n\n\n\n\n#### do(func, times, showResult=True)\n\nExecutes the specified parameter function `func` `times` amount of times. If showResult=True, it returns a list of the results.\n\nExample usage:\n\n```python\ndo(lambda : print(\"hello\"), 5) #Will print \"hello\" 5 times\n```\n\n#### doall(func, args, showResult=True)\n\nExecutes the given function for a list of arguments.\n\nExample usage:\n\n```python\ndo(addFive, [1,2,3],True) #Returns [6,7,8]\n```\n\n\n#### dorec(func, times, args=None, showResult=True)\n\nRecursively executes the given function, taking the previous output of the parameter function `func` as parameter.\n\nIf the args param is not a list, tuple or dictionary, but the return value is, it will loop through all the returned values and apply the parameter function on them recursively until the remaining specified recursion depth is reached.\nThis is determined by the `times` parameter and the current level of recursion.\nFor example, if times=10 and the third iteration produces a list, the parameter function will be applied on the contents of that list 7 more times.\n\n\n\n### Type Check Shorthands\n\n\n\n#### isiter(item) / isiterable(item)\nChecks if the item is an iterable\n\n\n#### islist(item)\n```python\nisinstance(item,list)\n```\n\n#### isint(item)\n```python\nisinstance(item,int)\n```\n\n#### isfloat(item)\n```python\nisinstance(item,float)\n```\n\n#### isstring(item)\n```python\nisinstance(item,str)\n```\n\n#### isdict(item)\n```python\nisinstance(item,dict)\n```\n\n#### istuple(item)\n```python\nisinstance(item,tuple)\n```\n\n#### getType(item)\nReturns the type of that item as a string.\n\n\n\n### Iterables\n\n\n\n\n\n#### inany(iterable, item, searchInSubstring=False)\nRecursively iterates through the target iterable and all nested iterables, meaning it will also check:\n\n- All sublists, sublists of sublists, etc. for ALL iterables (lists, tuples, user-defined iterables)\n\n- For dictionaries, it checks both the keys and the values, including any nested iterables within the values\n\n- If searchInSubstring=True, it will also check if the `item` is a substring of any element.\n\n\nExample usage:\n```python\nb = {\"test\" : 3, \"other\" : [1,2,[3,{\"yo\" : [3,\"MisterL\"]},4],5]}\ninany(b,\"ister\") #False\ninany(b,\"ister\",True) #True, as \"ister\" is a substring of \"MisterL\"\n```\n\n#### allIn(lst, otherlst)\nChecks if **all** of the elements from `lst` are in `otherlst`\n\n#### anyIn(lst, otherlst)\nChecks if **any** of the elements from `lst` are in `otherlst`\n\n#### toDict(lst, otherlst)\nCombines two lists into a dictionary, with `lst` as keys and `otherlst` as values. \nIf the two lists are of different size, the excess values in the longer list are discarded.\n\n\n\n### Parsing\n\n\n\n#### intput(msg, error=None) -> int\n\nShorthand for `int(input(msg))`, but also handles any potential exceptions resulting from unexpected user input, such as strings, floats and unsupported unicode characters. It will continue asking the message `msg` until it receives a valid answer. \nIf the parameter `error` is supplied, it will also print that error message after each invalid input.\nThis function is guaranteed to return an integer.\n\n\n#### numparse(string, decimals=False, decimalPoint='.', negatives=True)\nParses all numbers out of a given string and returns them in a list. Will return an empty list if there are no numbers in the string. \nIf negatives=False, all `-` signs will be ignored and only positive numbers returned. \nIf decimals=True, it will also parse out decimals numbers using the `decimalPoint`. `decimalPoint` can also be set to different values, e.g. ',' when parsing German numbers.\n\nExample usage\n```python\nnumparse(\"oeiajoefijaoi23jjaeofijaeof83fjoaefij9aeoiafj\") #Returns [23, 83, 9]\nnumparse(\"abaefjoi23.6ojaeoifjaojo36.5152aeof124ijeoafji3oij\",True) #Returns [23.6, 36.5152, 124.0, 3.0]\nnumparse(\"aojefioeojf23,33joijwoeifjaoiefjaoij99,99eaf,,,.f13\",True,\",\") #Returns [23.33, 99.99, 13.0]\n```\n\n#### timeparse(timestring)\nExpects a string in format HH:MM or HH:MM:SS \nReturns a datetime object (with or without seconds) from the parameter string\n\n\n#### dateparse(datestring, seperator='-', reverse=False, american=False)\nExpects a datestring in a standard format (e.g. YYYY-MM-DD, YY-M-DD, etc.) \nThe seperator can be changed to parse different notations, e.g. 2019/08/12 \nIf reverse=True, parses a date of format DD-MM-YYYY or similar \nIf american=True, expects YYYY-DD-MM (or MM-DD-YYYY if reverse=True) or similar format \n\n\n## Files\nShorthands for simple file operations.\n### Shorthands\n\n#### fileappend(filename, thing)\nWill open the file and append the `thing` to the end of the file. Will convert to string if necessary and close file after use.\n\n#### fileoverwrite(filename, thing)\nWill open the file and overwrite the file contents with the `thing`. Will convert to string if necessary and close file after use.\n\n#### filereplace(filename, regexToReplace, replacementString)\nWill open the file and replace anything that matches the regex `regexToReplace` with the `replacementString`. Closes file after use.\n\n## Haskell\nImplements common Haskell convenience features\n\n### List features\nAll except `product` work on strings as well.\n\n#### take(lst, amount)\nReturns the first `amount` indexes of the `lst`\n\n#### drop(lst,amount)\nReturns the last `amount` indexes of the `lst`\n\n#### last(lst)\nReturns the last index of `lst`\n\n#### head(lst)\nReturns the first index of `lst`\n\n#### init(lst)\nReturns all indexes of `lst` except for the last.\n\n#### tail(lst)\nReturns all indexes of `lst` except for the first.\n\n#### product(lst)\nReturns the product of all members of the list multiplied together. Somewhat similar to built-in function `sum()`\n\n#### cycle(thing, amount)\nCycles a list or string and returns the first `amount` characters from it.\n```python\ncycle(\"TEST\",3)\n```\nis effectively equal to\n```haskell\ntake 3 (cycle \"TEST\")\n```\n\nExample usage:\n```python\ncycle(\"TEST \",17) #Returns 'TEST TEST TEST TE'\ncycle([1,2,3,4],10) #Returns [1, 2, 3, 4, 1, 2, 3, 4, 1, 2]\n```\n\n#### replicate(thing, amount)\nReplicates the given thing and returns a list containing the object `amount` times.\n\nExample usage:\n```python\nreplicate(15,3) #Returns [15, 15, 15]\nreplicate(True,3) #Returns [True, True, True]\nreplicate(\"Hello\",5) #Returns ['Hello', 'Hello', 'Hello', 'Hello', 'Hello']\nreplicate([1,2,3,4],3) #Returns [[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]]\n```\n\n\n## Math\nAn extension to the built-in math module\n\n### Numbers\n\n#### isPrime(num)\nChecks if the given number is a prime.\n\n#### findPrimes(minimum,maximum)\nReturns all in `range(minimum,maximum)`\n\n#### findFactors(num)\nReturns a list of all factors of the given number, including 1 and the number itself. \nExample usage:\n```python\nfindFactors(120) #Returns [1, 120, 2, 60, 3, 40, 4, 30, 5, 24, 6, 20, 8, 15, 10, 12]\nfindFactors(67) #Returns [1, 67]\n```\n\n#### findFactorTuples(num)\nReturns all factors of the given number in a list of tuples, including 1 and the number itself. \nExample usage:\n```python\nfindFactors(120) #Returns [(1, 120), (2, 60), (3, 40), (4, 30), (5, 24), (6, 20), (8, 15), (10, 12)]\nfindFactors(67) #Returns [(1, 67)]\n```\n\n#### findIntegerRoot(num,power=2)\nFinds the integer x, such that x \\*\\* `power` is equal to `num`. Returns None if there is no integer root. \nExample usage:\n```python\nfindIntegerRoot(100) #Returns 10\nfindIntegerRoot(27,3) #Returns 3\nfindIntegerRoot(16807,5) #Returns 7\nfindIntegerRoot(13) #Returns None\n```\n\n### 2D Linear equations\n\n#### findIntersect(eq1,eq2)\nExpects two equations in the tuple form (m,c) aka (gradient,start) for a linear equation of type `y = mx + c`. \nReturns a tuple with values (x,y) representing the Cartesian coordinates at which these two equations are equal. \n\n#### findGradient(coord1,coord2)\nExpects two position vectors in tuple form (x,y). \nReturns the gradient of the line connecting them\n\n### 2D Geometry\n\n#### circlePerimeter(radius)\nReturns the perimeter of a circle with given `radius`.\n\n#### triangleArea(a,b,c=None)\n**Either** expects three parameters representing the three sides of the triangle, \n**or** expects two parameters representing the base length and height of the triangle. \nReturns the area of the triangle.\n\n#### circleArea(radius)\nReturns the area of a circle with given `radius`.\n\n#### trapezoidArea(a,b,d)\nExpects the lengths of the parallel sides `a` and `b`, as well as the distance between them `d`. \nReturns the area of the trapezoid.\n\n### 3D Geometry\n\n#### sphereVolume(radius)\nReturns the volume of a sphere with the given `radius`.\n\n#### prismVolume(a,b,c=None)\n**Either** expects three parameters representing length, width and height of the prism, \n**or** expects two parameters representing the area of the base and the height of the prism \nReturns the volume of the prism.\n\n#### cylinderVolume(radius, height)\nReturns the volume of a cylinder with given `radius` and `height`.\n\n#### pyramidVolume(area, height)\nReturns the volume of a pyramid with given `area` and `height`.\n\n#### coneVolume(area, height)\nReturns the volume of a cone with given `area` and `height`.\n\n## Data structures\nAdditional complex data structures for Python.\n\n### TreeNode\n\n### Methods\n\n#### Node.addValue(self,valueiterable)\nAdds all values of the valueiterable to the tree, **starting from that Node**\n\n#### Node.findValue(self,value,returnNode=False)\nReturns True if the `value` can be found **downwards of that Node**, False if it cannot. \nIf returnNode=True, it instead returns the Node with that value, or None.\n\n#### Node.findNode(self,value)\nShorthand for Node.findValue(self,value,returnNode=True)\n\n#### Node.getSubNodeKeys(self)\nReturns a list of all the values of the subNodes\n\n### Fields\n\n#### Node.subNodes\nReturns a dictionary of {value:SubNode}\n\n\n### Explanation\n\nFor example, the string \"TEST\" has 4 elements and would be converted into a tree with 4 Nodes:\n\n \"T\" -> \"E\" -> \"S\" -> \"T\"\n\n Node(value=\"T\") ---> Node(value=\"E\") ---> Node(value=\"S\") ---> Node(value=\"T\")\n\nIf we now add the string \"TEA\" to the same tree, we get:\n\n \"T\" -> \"E\" -> \"S\" -> \"T\"\n -> \"A\"\n\nThe second Node (with value \"E\") now has two SubNodes, one with value \"S\" and one with value \"A\" \nThe values \"T\" and \"E\" are not added a second time, as they are already in the tree.\n\n### Full example\n\n```python\n#Create TreeNode object\nmaster = TreeNode()\n\n#Add values to the tree\nmaster.addValue(\"hello\")\nmaster.addValue(\"hey\")\nmaster.addValue(\"hi\")\nmaster.addValue(\"howdy\")\n```\n\nNow our tree looks like this:\n\n \"h\" -> \"e\" -> \"l\" -> \"l\" -> \"o\"\n -> \"y\"\n -> \"i\"\n -> \"o\" -> \"w\" -> \"d\" -> \"y\"\n\n\n```python\n#Check if \"hey\" is really in the tree\nmaster.findValue(\"hey\") #Returns True\n\n#Get the Node that contains the 'd' in \"howdy\"\nnode = master.findNode(\"howd\")\n\n#Get the Node that contains the 'e' in \"hey\" (and also the 'e' in \"hello\")\notherNode = master.findNode(\"he\")\n```\n\nIf we call a method on a node of the tree, we call it **from that position** \nSo, for example:\n\n```python\nmaster.findValue(\"hello\") #Returns True\n\notherNode.findValue(\"hello\") #Returns False\n#There is no \"hello\" downwards of \"he\".\n#So if we wanted to get to \"hello\" from \"he\", we would need to search for \"llo\"\n\notherNode.findValue(\"llo\") #Returns True\n\n#The same applies to adding values, so the following two calls are identical:\nmaster.addValue(\"here\")\notherNode.addValue(\"re\")\n```\n\nNow our tree looks like this:\n\n \"h\" -> \"e\" -> \"l\" -> \"l\" -> \"o\"\n -> \"y\"\n -> \"r\" -> \"e\"\n -> \"i\"\n -> \"o\" -> \"w\" -> \"d\" -> \"y\"\n\nWhat if we want to find all SubNodes of a Node, e.g. of the \"e\" from \"he\" (which would be 'l', 'y', 'r')\n\n```python\notherNode.subNodes\n#Returns {'l':, 'y':, 'r':}\n\n#If we wanted to get the Node of the 'r' that follows this Node, we could do the following\nyetAnotherNode = otherNode.subNodes['r']\n\n#This achieves the same as calling\nyetAnotherNode = otherNode.findNode(\"r\")\n```\n\nWhat if we just want the values of the SubNodes, without dealing with the objects themselves?\n\n```python\notherNode.getSubNodeKeys()\n#Returns ['l','y','r']\n```\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/MisterL2/python-util", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "python-util", "package_url": "https://pypi.org/project/python-util/", "platform": "", "project_url": "https://pypi.org/project/python-util/", "project_urls": { "Homepage": "https://github.com/MisterL2/python-util" }, "release_url": "https://pypi.org/project/python-util/1.2/", "requires_dist": null, "requires_python": "", "summary": "A small python utilities addon", "version": "1.2" }, "last_serial": 5810080, "releases": { "1.0.1": [ { "comment_text": "", "digests": { "md5": "12c813ca598e608e4c4a2402a8f04058", "sha256": "33a1bafcb6497f9fa59acd5fbac20bcb4fdca3b5a6b2ac4a49868069e641d776" }, "downloads": -1, "filename": "python_util-1.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "12c813ca598e608e4c4a2402a8f04058", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 12084, "upload_time": "2019-05-09T16:20:45", "url": "https://files.pythonhosted.org/packages/f1/29/d06af9f83b63e1237a655eb4e15b3d0186229b2996dfb1d4ca1812c0bd4e/python_util-1.0.1-py3-none-any.whl" } ], "1.1": [ { "comment_text": "", "digests": { "md5": "13bed51b5d05107d16e6ae12756a78d1", "sha256": "0f6f368ad68c7657f28c86f9a36c50f3b2f02a46b7e99ffd4dc1a3db7a5e7ac0" }, "downloads": -1, "filename": "python_util-1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "13bed51b5d05107d16e6ae12756a78d1", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11114, "upload_time": "2019-05-09T20:45:31", "url": "https://files.pythonhosted.org/packages/aa/85/c274c1e4ea7166b975cbce0ddb5af19245e6ed14bdafac52335e012209b2/python_util-1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "671b078a945dcf8f78b18bf2fd58dbce", "sha256": "38f04cf7611591fbb2410a9755995f801a2679a40131beb68daa5edf95af185a" }, "downloads": -1, "filename": "python-util-1.1.tar.gz", "has_sig": false, "md5_digest": "671b078a945dcf8f78b18bf2fd58dbce", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12034, "upload_time": "2019-05-09T20:45:32", "url": "https://files.pythonhosted.org/packages/1c/15/afebbd179dfac5b340b0415937e1eda3983e8319c5e0bfe2d89e9e0b87fa/python-util-1.1.tar.gz" } ], "1.1.1": [ { "comment_text": "", "digests": { "md5": "e0023a07633f2bce192b55fe1fbbc703", "sha256": "a213dea5acc879ba23a27a2feb033626c15a66725e12995908e558dc93544505" }, "downloads": -1, "filename": "python_util-1.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "e0023a07633f2bce192b55fe1fbbc703", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11150, "upload_time": "2019-05-09T22:01:37", "url": "https://files.pythonhosted.org/packages/f1/91/31ea67d1586a62f3bd1ebfe268a68cacaf0b026d2bed88b38b70fd82754f/python_util-1.1.1-py3-none-any.whl" } ], "1.2": [ { "comment_text": "", "digests": { "md5": "fa786777fe7fa4bb2dde557d23dc38e2", "sha256": "71e1dbd48abe5939bf424b8781e411141bb0bdd646ea1f8d96fe55019f52c023" }, "downloads": -1, "filename": "python_util-1.2-py3-none-any.whl", "has_sig": false, "md5_digest": "fa786777fe7fa4bb2dde557d23dc38e2", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11620, "upload_time": "2019-09-10T16:51:33", "url": "https://files.pythonhosted.org/packages/3f/69/2b2f7d187fcaca34fd720be46704211780450715bb19f2844f682f5a4e7a/python_util-1.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ac351f170788e3e0b9a42079d05744d7", "sha256": "c20bc36c1d69044b852f8ab38e0614a8a3021a12b4e57bde44f4f0794517a55b" }, "downloads": -1, "filename": "python-util-1.2.tar.gz", "has_sig": false, "md5_digest": "ac351f170788e3e0b9a42079d05744d7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12873, "upload_time": "2019-09-10T16:51:36", "url": "https://files.pythonhosted.org/packages/c8/2f/b10deeffd664186fd4ad3315a3382a365e813bdee7169e74970399687baf/python-util-1.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "fa786777fe7fa4bb2dde557d23dc38e2", "sha256": "71e1dbd48abe5939bf424b8781e411141bb0bdd646ea1f8d96fe55019f52c023" }, "downloads": -1, "filename": "python_util-1.2-py3-none-any.whl", "has_sig": false, "md5_digest": "fa786777fe7fa4bb2dde557d23dc38e2", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11620, "upload_time": "2019-09-10T16:51:33", "url": "https://files.pythonhosted.org/packages/3f/69/2b2f7d187fcaca34fd720be46704211780450715bb19f2844f682f5a4e7a/python_util-1.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ac351f170788e3e0b9a42079d05744d7", "sha256": "c20bc36c1d69044b852f8ab38e0614a8a3021a12b4e57bde44f4f0794517a55b" }, "downloads": -1, "filename": "python-util-1.2.tar.gz", "has_sig": false, "md5_digest": "ac351f170788e3e0b9a42079d05744d7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12873, "upload_time": "2019-09-10T16:51:36", "url": "https://files.pythonhosted.org/packages/c8/2f/b10deeffd664186fd4ad3315a3382a365e813bdee7169e74970399687baf/python-util-1.2.tar.gz" } ] }