{ "info": { "author": "Dmitry Shachnev", "author_email": "mitya57@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python :: 3 :: Only" ], "description": ".. image:: https://api.travis-ci.org/mitya57/infseq.svg\n :target: https://travis-ci.org/mitya57/infseq\n :alt: Travis CI status\n\nInfinite sequences for Python\n=============================\n\nThe ``infseq`` module implements cached lazy infinite sequences for Python 3.\n\nHere, the word \u201clazy\u201d means that values of the sequence will never be calculated\nunless they are really used, and the word \u201ccached\u201d means that every value will\nbe calculated no more than once.\n\nSequences can contain items of any type \u2014 such as numbers, strings or even\nother sequences.\n\nUsing this module is pretty straightforward \u2014 everything just works. Here are\nsome usage examples:\n\nCreating sequences\n------------------\n\n.. code:: python\n\n >>> from infseq import InfSequence\n >>> InfSequence(5)\n \n >>> InfSequence(5, 6, ...)\n \n >>> InfSequence(lambda index: index * 2 + 1)\n \n >>> InfSequence.geometric_progression(3)\n \n >>> InfSequence.cycle('a', 'b', 'c')\n \n >>> InfSequence.fibonacci()\n \n\n**Note**: for the ease of debugging the first six values are calculated when\n``repr()`` is called on the sequence. If you just create the sequence without\nprinting it, the values are not calculated. The number of items can be adjusted\nby modifying the ``infseq.REPR_VALUES`` number (it is set to 6 by default).\n\nRetrieving the values\n---------------------\n\n.. code:: python\n\n >>> a = InfSequence.geometric_progression(2)\n >>> a\n \n >>> a[10]\n 1024\n >>> a.partial_sum(10) # a[0] + ... + a[9]\n 1023\n >>> a.partial_sum(4, 10) # sum(a[i] for i in range(4, 10))\n 1008\n >>> a.partial_product(5) # a[0] * ... * a[4]\n 1024\n\nSlicing and prepending elements\n-------------------------------\n\n.. code:: python\n\n >>> a[5:]\n \n >>> a[::2]\n \n >>> list(a[5:10]) # a[5:10] returns a map object, because of laziness\n [32, 64, 128, 256, 512]\n >>> list(a[4::-1]) # reverse slices also work\n [16, 8, 4, 2, 1]\n >>> (5, 7) + a\n \n\nArithmetic operations\n---------------------\n\n.. code:: python\n\n >>> b = InfSequence(1, 2, ...)\n >>> b\n \n >>> b * 2\n \n >>> b ** 2\n \n >>> a + b\n \n\nApplying any functions\n----------------------\n\n.. code:: python\n\n >>> c = InfSequence.geometric_progression(9)\n >>> c\n \n >>> import math\n >>> c.apply_function(math.sqrt)\n \n\nUsing the ``accumulate`` method\n-------------------------------\n\nThe ``accumulate`` method returns a sequence of partial sums of the original\nsequence (similar to itertools.accumulate_)::\n\n result[0] = a[0]\n result[1] = a[0] + a[1]\n result[2] = a[0] + a[1] + a[2]\n ...\n\n.. _itertools.accumulate: https://docs.python.org/3/library/itertools.html#itertools.accumulate\n\nIf a custom function is passed as an argument, it is used to do\nthe reducing instead of the sum function.\n\nIn the examples below we can get the sequence of *n(n+1)/2* and the sequence of\n*n!* using this method:\n\n.. code:: python\n\n >>> from operator import mul\n >>> b\n \n >>> b.accumulate()\n \n >>> b.accumulate(mul)\n \n\nUsing the matrix multiplication operator\n----------------------------------------\n\nIf you are using Python 3.5+, you can use the new \u201cmatrix multiplication\u201d\noperator that was introduced in that version.\n\nThe expression ``a @ b`` will produce the following result::\n\n result[0] = a[0] * b[0]\n result[1] = a[0] * b[1] + a[1] * b[0]\n result[2] = a[0] * b[2] + a[1] * b[1] + a[2] * b[0]\n ...\n\nExample:\n\n.. code:: python\n\n >>> InfSequence(0, 2, ...) @ InfSequence(1)\n \n\nInstalling the module and running the tests\n-------------------------------------------\n\nThe module is available on PyPI_. To install the module, simply use::\n\n pip3 install infseq\n\nThe source code is hosted on GitHub_.\n\nTo run the doctests in this module, use::\n\n python3 -m doctest ./README.rst\n\n.. _PyPI: https://pypi.python.org/pypi/infseq\n.. _GitHub: https://github.com/mitya57/infseq", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/mitya57/infseq", "keywords": null, "license": "BSD", "maintainer": null, "maintainer_email": null, "name": "infseq", "package_url": "https://pypi.org/project/infseq/", "platform": "any", "project_url": "https://pypi.org/project/infseq/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/mitya57/infseq" }, "release_url": "https://pypi.org/project/infseq/0.2/", "requires_dist": null, "requires_python": null, "summary": "Lazy infinite cached sequences", "version": "0.2" }, "last_serial": 1860064, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "8fd99fe63d9671fe2bcbf641251184b2", "sha256": "53942d6a9b0243a009547d5986d671c0e9d0c54eb1b04c67e63d66a383216881" }, "downloads": -1, "filename": "infseq-0.1.tar.gz", "has_sig": true, "md5_digest": "8fd99fe63d9671fe2bcbf641251184b2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4705, "upload_time": "2015-12-10T17:22:02", "url": "https://files.pythonhosted.org/packages/8e/d3/c5f347ec80a56b3a024519531cdf251771c8408db6eb65e60abc5d0b5bf0/infseq-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "e1604924c4ba69ac856a529094331649", "sha256": "32076dcc0618d9289437d551166e2fa354a53f290746ef0a85574dd2ad11e5b1" }, "downloads": -1, "filename": "infseq-0.2.tar.gz", "has_sig": true, "md5_digest": "e1604924c4ba69ac856a529094331649", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5284, "upload_time": "2015-12-13T15:05:23", "url": "https://files.pythonhosted.org/packages/23/71/0755016aa3fefddafc1d4b62c7ae7e906b6592aaafc2a8fb5b6007256181/infseq-0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "e1604924c4ba69ac856a529094331649", "sha256": "32076dcc0618d9289437d551166e2fa354a53f290746ef0a85574dd2ad11e5b1" }, "downloads": -1, "filename": "infseq-0.2.tar.gz", "has_sig": true, "md5_digest": "e1604924c4ba69ac856a529094331649", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5284, "upload_time": "2015-12-13T15:05:23", "url": "https://files.pythonhosted.org/packages/23/71/0755016aa3fefddafc1d4b62c7ae7e906b6592aaafc2a8fb5b6007256181/infseq-0.2.tar.gz" } ] }