{ "info": { "author": "Sheng Zhong", "author_email": "zhsh@umich.edu", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3" ], "description": "## Binary Search in Python\n\nBinary search on already sorted sequences (list, tuple) to get the first element `>=` or `>`\na value (similar to C++'s `std::lower_bound` and `std::upper_bound`).\n\nRequires python >=3.5 for the `typing` module and >= 3.4 for the `enum` module, but you can easily\nextract the `search` function from `binary_search/__init__.py` if you need it for a lower version.\n\n## Install\n1. `pip install binary-search`\n\n## Usage\nSee `tests.py` for more sample usage.\n```python\nimport binary_search as bs\n\nsorted_sequence = (2, 5, 7, 9)\na = bs.search(sorted_sequence, 5)\nprint(a) # 1 - the index of the first element >= 5\n\nb = bs.search(sorted_sequence, 6)\nprint(b) # 2 - the index of the first element >= 6 (element 2 with value 7)\n```\n\nYou can also use a custom key in the same way as `sorted`\n```python\nimport binary_search as bs\nimport random\n\n# sequence of 10 random pairs of integers\nsequence = [(random.randint(), random.randint()) for _ in range(10)]\n# sort and search just using the first integer\nkey = lambda pair: pair[0]\n\nsorted_sequence = sorted(sequence, key=key)\nbs.search(sorted_sequence, [5, None], key=key)\n```\n\n## Development and testing\n1. Fork the repository\n2. Clone your fork\n3. Install it in editable mode `pip install -e .`\n4. Make any changes and add new tests to `tests.py`\n5. Run pytest `python -m pytest`\n6. Commit and push to your fork\n7. Make pull request (merge your fork back to main repo)", "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/LemonPi/python_binary_search", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "binary-search", "package_url": "https://pypi.org/project/binary-search/", "platform": "", "project_url": "https://pypi.org/project/binary-search/", "project_urls": { "Homepage": "https://github.com/LemonPi/python_binary_search" }, "release_url": "https://pypi.org/project/binary-search/0.3.0/", "requires_dist": null, "requires_python": ">=3.5.*", "summary": "Binary search on python sorted sequences", "version": "0.3.0" }, "last_serial": 4150796, "releases": { "0.3.0": [ { "comment_text": "", "digests": { "md5": "b04fa6bfcdc3e1ec8b8e708be77f0705", "sha256": "ed41a3e49a4b0fbb21d8c32c8943f3d220b0eb01db49f89caf5d80efbdd6b298" }, "downloads": -1, "filename": "binary_search-0.3.0.tar.gz", "has_sig": false, "md5_digest": "b04fa6bfcdc3e1ec8b8e708be77f0705", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5.*", "size": 2655, "upload_time": "2018-08-08T21:30:52", "url": "https://files.pythonhosted.org/packages/6a/e8/120de6ce10e8912d4623a5750089a5c17d44f9b3dd60fb89ab5b2e0775a0/binary_search-0.3.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "b04fa6bfcdc3e1ec8b8e708be77f0705", "sha256": "ed41a3e49a4b0fbb21d8c32c8943f3d220b0eb01db49f89caf5d80efbdd6b298" }, "downloads": -1, "filename": "binary_search-0.3.0.tar.gz", "has_sig": false, "md5_digest": "b04fa6bfcdc3e1ec8b8e708be77f0705", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5.*", "size": 2655, "upload_time": "2018-08-08T21:30:52", "url": "https://files.pythonhosted.org/packages/6a/e8/120de6ce10e8912d4623a5750089a5c17d44f9b3dd60fb89ab5b2e0775a0/binary_search-0.3.0.tar.gz" } ] }