{ "info": { "author": "Elias Dorneles", "author_email": "eliasdorneles@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 2 - Pre-Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Natural Language :: English", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4" ], "description": "===============================\r\nJK python library\r\n===============================\r\n\r\n.. image:: https://badge.fury.io/py/jk.png\r\n :target: http://badge.fury.io/py/jk\r\n\r\n.. image:: https://travis-ci.org/eliasdorneles/jk.png?branch=master\r\n :target: https://travis-ci.org/eliasdorneles/jk\r\n\r\n.. image:: https://pypip.in/d/jk/badge.png\r\n :target: https://pypi.python.org/pypi/jk\r\n\r\n\r\nLibrary containing useful functions for manipulating iterables.\r\n\r\n.. note:: \r\n This code is deprecated, don't use it!\r\n Use `toolz.itertoolz `_ instead.\r\n\r\nInspiration was drawn from Python itertools' recipes and Ruby's Enumerable API.\r\n\r\nWorks on Python 2.6+ and 3.x.\r\n\r\n* Free software: BSD license\r\n* Documentation: https://jk.readthedocs.org.\r\n\r\nFeatures\r\n--------\r\n\r\neach_cons\r\n:::::::::\r\n\r\n* ``each_cons(sequence, size)``\r\n\r\nIterates lazily through a sequence, yielding a sliding window\r\nwith the given size for each iteration.\r\n\r\nExamples:\r\n\r\n\r\nCalculating quarterly sales report::\r\n\r\n >>> import jk\r\n >>> month_sales = [123.45, 54.3, 428.1, 144.2, 245.45, 197.3]\r\n >>> for a, b, c in jk.each_cons(month_sales, 3):\r\n ... print '%0.2f' % ((a + b + c)/3)\r\n ...\r\n 201.95\r\n 208.87\r\n 272.58\r\n 195.65\r\n\r\nFind duplicated lines in a file::\r\n\r\n >>> lines = \"\"\"here is a simple\r\n ... file for us to test.\r\n ... this line repeats\r\n ... this line repeats\r\n ... -- this one does not\r\n ... this one repeats too\r\n ... this one repeats too\r\n ... okay, we're done here\"\"\".split('\\n')\r\n >>>\r\n >>> for ln, (a, b) in enumerate(jk.each_cons(lines, 2), 1):\r\n ... if a == b:\r\n ... print (ln, a)\r\n ...\r\n (3, 'this line repeats')\r\n (6, 'this one repeats too')\r\n\r\n\r\n\r\nslice_before and slice_after\r\n::::::::::::::::::::::::::::\r\n\r\n* ``slice_before(predicate, sequence)``\r\n* ``slice_after(predicate, sequence)``\r\n\r\nThese functions are useful when you have a stream that has some sort of delimiter.\r\nHandy for parsing log files, for example.\r\n\r\nThey iterate lazily through a sequence, yielding a tuple containing the elements\r\nsliced just before (or after) the predicate evaluates to True.\r\n\r\nThe predicate argument can also be a string or a regular expression pattern\r\nto be matched against the sequence elements.\r\n\r\nExamples:\r\n\r\nGrouping numbers until reaching zero::\r\n\r\n >>> numbers = [1, 2, 3, 0, 4, 5, 0, 6, 0, 7, 8]\r\n >>> print list(jk.slice_after(lambda x: x == 0, numbers))\r\n [(1, 2, 3, 0), (4, 5, 0), (6, 0), (7, 8)]\r\n\r\nReading entries of a fantasy multiline log file::\r\n\r\n >>> log_lines = \"\"\"START: initiating...\r\n ... kernel found\r\n ... EVENT: started\r\n ... moving on\r\n ... EVENT: something happened\r\n ... EVENT: another thing happened\"\"\".split('\\n')\r\n >>>\r\n >>> for entry in jk.slice_before('^(START|EVENT):', log_lines):\r\n ... print entry\r\n ...\r\n ('START: initiating...', 'kernel found')\r\n ('EVENT: started', 'moving on')\r\n ('EVENT: something happened',)\r\n ('EVENT: another thing happened',)\r\n\r\nfirst, second and nth\r\n:::::::::::::::::::::\r\n\r\n* ``first(sequence, default=None)``\r\n\r\nReturns the first element of a sequence\r\n(or a default value if the sequence is empty).\r\n\r\n* ``second(sequence, default=None)``\r\n\r\nReturns the second element of a sequence\r\n(or a default value if not exists).\r\n\r\n* ``nth(sequence, n, default=None)``\r\n\r\nReturns the nth element of a sequence\r\n(or a default value if not exists).\r\n\r\nNote that the argument n is not a zero-based index: it is a ordinal number,\r\nso n=1 means the first element, n=4 means the fourth and so on.\r\n\r\n\r\n\r\n\r\n\r\nHistory\r\n-------\r\n\r\n0.1.0 (2014-11-23)\r\n---------------------\r\n\r\n* First release on PyPI.", "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/eliasdorneles/jk", "keywords": "jk", "license": "BSD", "maintainer": "", "maintainer_email": "", "name": "jk", "package_url": "https://pypi.org/project/jk/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/jk/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/eliasdorneles/jk" }, "release_url": "https://pypi.org/project/jk/0.1.0/", "requires_dist": null, "requires_python": null, "summary": "Library containing useful functions for manipulating iterables", "version": "0.1.0" }, "last_serial": 1534993, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "c956717951dc880b22718ae81e9987ac", "sha256": "8d9d1cd49a2ebc9b03c312a582fb5c339881362ceb8ff82463ac189fdc014c47" }, "downloads": -1, "filename": "jk-0.1.0.tar.gz", "has_sig": false, "md5_digest": "c956717951dc880b22718ae81e9987ac", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14291, "upload_time": "2014-11-22T23:21:53", "url": "https://files.pythonhosted.org/packages/2b/03/058205838ea6739b3ed9cf67485bc6b28a197450c26a06c0aa47a6c27d38/jk-0.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "c956717951dc880b22718ae81e9987ac", "sha256": "8d9d1cd49a2ebc9b03c312a582fb5c339881362ceb8ff82463ac189fdc014c47" }, "downloads": -1, "filename": "jk-0.1.0.tar.gz", "has_sig": false, "md5_digest": "c956717951dc880b22718ae81e9987ac", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14291, "upload_time": "2014-11-22T23:21:53", "url": "https://files.pythonhosted.org/packages/2b/03/058205838ea6739b3ed9cf67485bc6b28a197450c26a06c0aa47a6c27d38/jk-0.1.0.tar.gz" } ] }