{ "info": { "author": "Vincent Driessen", "author_email": "vincent@3rdcloud.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.0", "Programming Language :: Python :: 3.1", "Programming Language :: Python :: 3.2", "Programming Language :: Python :: 3.3", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "pluck: Quickly pluck \"fields\" from a list of values\n===================================================\n\n.. image:: https://travis-ci.org/nvie/pluck.png\n :target: https://travis-ci.org/nvie/pluck\n\n\npluck is the simplest way of plucking \"fields\" from an iterable of values.\n\"Fields\" are either ``item.field`` or ``item[field]``. Pluck tries both,\nin that order. If nothing is found, and no default value is specified, it\nthrows an exception.\n\n\nUsage\n=====\n\nThe package consists of one module consisting of two functions::\n\n from pluck import pluck, ipluck\n\n``ipluck`` is just the iterable version of ``pluck``. Use it like this::\n\n pluck(iterable, key)\n\nor::\n\n pluck(iterable, *keys)\n\n\nExamples\n========\n\nA simple example first. Say you have a list of datetimes::\n\n >>> from pluck import pluck\n >>> dates = [\n ... datetime(2012, 10, 22, 12, 00),\n ... datetime(2012, 10, 22, 15, 14),\n ... datetime(2012, 10, 22, 21, 44),\n ... ]\n >>> pluck(dates, 'day')\n [22, 22, 22]\n >>> pluck(dates, 'hour')\n [12, 15, 21]\n\nIt also works on dictionary-like access (``__getitem__``)::\n\n >>> objects = [\n ... {'id': 282, 'name': 'Alice', 'age': 30, 'sex': 'female'},\n ... {'id': 217, 'name': 'Bob', 'age': 56},\n ... {'id': 328, 'name': 'Charlie', 'age': 56, 'sex': 'male'},\n ... ]\n >>> pluck(objects, 'name')\n ['Alice', 'Bob', 'Charlie']\n >>> pluck(objects, 'age')\n [30, 56, 56]\n\nYou can also combine these into a single pluck::\n\n >>> pluck(objects, 'name', 'age')\n [('Alice', 30), ('Bob', 56), ('Charlie', 56)]\n\n\nDefaults\n========\n\nYou can specify default values, too. By default, ``pluck`` will throw an\nexception when a \"field\" does not exist::\n\n >>> pluck(objects, 'sex')\n Traceback (most recent call last):\n File \"\", line 1, in \n File \"pluck.py\", line 104, in pluck\n return list(ipluck(iterable, *keys, **kwargs))\n File \"pluck.py\", line 49, in getter\n raise ValueError('Item %r has no attr or key for %r' % (item, key))\n ValueError: Item {'age': 56, 'id': 217, 'name': 'Bob'} has no attr or key for 'sex'\n\nTo instead fill these places with a default value, use this::\n\n >>> pluck(objects, 'sex', default='unknown')\n ['female', 'unknown', 'male']\n\nWhen you specify multiple keys, you need to use the ``defaults`` (plural!)\nkeyword argument instead::\n\n >>> pluck(objects, 'name', 'sex', defaults={'sex': 'unknown'})\n [('Alice', 'female'), ('Bob', 'unknown'), ('Charlie', 'male')]\n\n\nIterator, rather?\n=================\n\nUse ``ipluck`` if you'd rather wanna have an iterator::\n\n >>> from pluck import ipluck\n >>> ipluck(large_stream_of_items, 'name')\n \n\n``pluck`` is equivalent to ``list(ipluck(...))``.\n\n\nHistory\n=======\n\n0.2 (2012-10-22)\n------------------\n - Add Python 3 compatibility\n - Improve documentation\n\n0.1 (2012-10-22)\n------------------\n - Initial release.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/nvie/pluck/", "keywords": null, "license": "BSD", "maintainer": null, "maintainer_email": null, "name": "pluck", "package_url": "https://pypi.org/project/pluck/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/pluck/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/nvie/pluck/" }, "release_url": "https://pypi.org/project/pluck/0.2/", "requires_dist": null, "requires_python": null, "summary": "Plucks values from an iterable.", "version": "0.2" }, "last_serial": 663301, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "7ffacaf264cec76a932e84adc898f8ed", "sha256": "1ed0c830216cbdb1e32187c8e35de15007a82baa4a86912396d7a50a84fbab3e" }, "downloads": -1, "filename": "pluck-0.1.tar.gz", "has_sig": false, "md5_digest": "7ffacaf264cec76a932e84adc898f8ed", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4015, "upload_time": "2012-10-22T10:57:20", "url": "https://files.pythonhosted.org/packages/c4/5a/15a999d5267f76d35d2aa7757790e5dbdf0eda7471f879131f19c857c360/pluck-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "ba2edbbee4feebecf4d62c193e7854bc", "sha256": "2a84a60ee6681b933d9b6757b3febbde4a200f2f6f65d396e214ad4ecab2efdf" }, "downloads": -1, "filename": "pluck-0.2.tar.gz", "has_sig": false, "md5_digest": "ba2edbbee4feebecf4d62c193e7854bc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4285, "upload_time": "2012-10-22T11:24:22", "url": "https://files.pythonhosted.org/packages/92/d5/d671e0130c8a11d43db8c532abcd4526413fd73a134c4d5cd2930fdafcc9/pluck-0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "ba2edbbee4feebecf4d62c193e7854bc", "sha256": "2a84a60ee6681b933d9b6757b3febbde4a200f2f6f65d396e214ad4ecab2efdf" }, "downloads": -1, "filename": "pluck-0.2.tar.gz", "has_sig": false, "md5_digest": "ba2edbbee4feebecf4d62c193e7854bc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4285, "upload_time": "2012-10-22T11:24:22", "url": "https://files.pythonhosted.org/packages/92/d5/d671e0130c8a11d43db8c532abcd4526413fd73a134c4d5cd2930fdafcc9/pluck-0.2.tar.gz" } ] }