{ "info": { "author": "Matthew Tardiff", "author_email": "mattrix@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.2", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy" ], "description": "group-by-attr |Version| |Build| |Coverage| |Health|\n===================================================================\n\n|Compatibility| |Implementations| |Format| |Downloads|\n\nGroup items in a sequence by the value of a shared attribute.\n\n.. code:: python\n\n group_by_attr(attr, items)\n\n\nInstallation:\n\n.. code:: shell\n\n $ pip install group-by-attr\n\n\nExample\n-------\n\nLet's say you want to group some \"Struct\" instances together.\n\n.. code:: python\n\n >>> from pprint import pprint\n >>> from collections import namedtuple\n >>> Struct = namedtuple('Struct', ('x', 'y', 'z'))\n >>> a, b, c = (\n ... Struct(x=1, y=1, z=1),\n ... Struct(x=1, y=2, z=2),\n ... Struct(x=1, y=1, z=3))\n\nIf we were to group these instances by the 'x' attribute, we should\nexpect a single group containing all three items:\n\n.. code:: python\n\n >>> pprint(group_by_attr(attr='x', items=(a, b, c)))\n {1: (Struct(x=1, y=1, z=1),\n Struct(x=1, y=2, z=2),\n Struct(x=1, y=1, z=3))}\n\nIf, instead, we were to group by 'y', we should expect a different\ngrouping:\n\n.. code:: python\n\n >>> pprint(group_by_attr(attr='y', items=(a, b, c)))\n {1: (Struct(x=1, y=1, z=1),\n Struct(x=1, y=1, z=3)),\n 2: (Struct(x=1, y=2, z=2),)}\n\nFinally, grouping by 'z' will result in three separate groups:\n\n.. code:: python\n\n >>> pprint(group_by_attr(attr='z', items=(a, b, c)))\n {1: (Struct(x=1, y=1, z=1),),\n 2: (Struct(x=1, y=2, z=2),),\n 3: (Struct(x=1, y=1, z=3),)}\n\nThis function can also use an alternate getattr, as long as it implements\nthe same interface (taking an item and an attribute name as arguments).\nFor example, you could group dictionaries:\n\n.. code:: python\n\n >>> pprint(group_by_attr(\n ... attr='x',\n ... items=(\n ... {'x': 1, 'y': 'a'},\n ... {'x': 2, 'y': 'b'},\n ... {'x': 1, 'y': 'c'}),\n ... getattr_fn=dict.__getitem__))\n {1: ({'x': 1, 'y': 'a'},\n {'x': 1, 'y': 'c'}),\n 2: ({'x': 2, 'y': 'b'},)}\n\n\n.. |Build| image:: https://travis-ci.org/themattrix/python-group-by-attr.svg?branch=master\n :target: https://travis-ci.org/themattrix/python-group-by-attr\n.. |Coverage| image:: https://img.shields.io/coveralls/themattrix/python-group-by-attr.svg\n :target: https://coveralls.io/r/themattrix/python-group-by-attr\n.. |Health| image:: https://landscape.io/github/themattrix/python-group-by-attr/master/landscape.svg\n :target: https://landscape.io/github/themattrix/python-group-by-attr/master\n.. |Version| image:: https://pypip.in/version/group_by_attr/badge.svg?text=version\n :target: https://pypi.python.org/pypi/group-by-attr\n.. |Downloads| image:: https://pypip.in/download/group_by_attr/badge.svg\n :target: https://pypi.python.org/pypi/group-by-attr\n.. |Compatibility| image:: https://pypip.in/py_versions/group_by_attr/badge.svg\n :target: https://pypi.python.org/pypi/group-by-attr\n.. |Implementations| image:: https://pypip.in/implementation/group_by_attr/badge.svg\n :target: https://pypi.python.org/pypi/group-by-attr\n.. |Format| image:: https://pypip.in/format/group_by_attr/badge.svg\n :target: https://pypi.python.org/pypi/group-by-attr\n", "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/themattrix/python-group-by-attr", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "group-by-attr", "package_url": "https://pypi.org/project/group-by-attr/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/group-by-attr/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/themattrix/python-group-by-attr" }, "release_url": "https://pypi.org/project/group-by-attr/1.0.1/", "requires_dist": null, "requires_python": null, "summary": "Group items in a sequence by the value of a shared attribute.", "version": "1.0.1" }, "last_serial": 1400492, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "d2a0f0a27a779e5ca79f305f22587031", "sha256": "927a562cf12d5105312f9d79f9978ba11c987a0c7cb50394c878926b1fec0fe2" }, "downloads": -1, "filename": "group_by_attr-1.0.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "d2a0f0a27a779e5ca79f305f22587031", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 2938, "upload_time": "2015-01-28T18:57:31", "url": "https://files.pythonhosted.org/packages/83/7a/927c032cb579cdc300b1db7491a77b6924099511eb32f7effe7f663e516a/group_by_attr-1.0.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "bd6365a197c94146e7936a76ec3223ed", "sha256": "f74d60957ce55336d35ca386982b9f7d2dd365fc8780430e3ce73a7cb39616a8" }, "downloads": -1, "filename": "group-by-attr-1.0.0.tar.gz", "has_sig": false, "md5_digest": "bd6365a197c94146e7936a76ec3223ed", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2109, "upload_time": "2015-01-28T18:57:29", "url": "https://files.pythonhosted.org/packages/1f/23/20864dcbdb6bd90c7adfa5de696965d15cf349aab9c7084845fb1243a429/group-by-attr-1.0.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "2134c1d659fea4935764398700723bb2", "sha256": "5e4c47ca34e3f1cfe233fd1a1366303693a1315e33503395495db63d2ba1228e" }, "downloads": -1, "filename": "group_by_attr-1.0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "2134c1d659fea4935764398700723bb2", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 2940, "upload_time": "2015-01-28T19:05:31", "url": "https://files.pythonhosted.org/packages/0d/a2/5b7fdd6673d045c97bf764294dcca0cf2149bc6f0ba2add69ce25c80c00b/group_by_attr-1.0.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a5780b7777cccd6f14e904e973f745d2", "sha256": "ad618711b9817ae37f7abd2073749834fd15b9ac133b92939566be2ca0048d0f" }, "downloads": -1, "filename": "group-by-attr-1.0.1.tar.gz", "has_sig": false, "md5_digest": "a5780b7777cccd6f14e904e973f745d2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2113, "upload_time": "2015-01-28T19:05:29", "url": "https://files.pythonhosted.org/packages/cb/a5/f5bfd3ae4b929345f2c33c9ed777a77cb5f7299ebad0abc387fb49eab3af/group-by-attr-1.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "2134c1d659fea4935764398700723bb2", "sha256": "5e4c47ca34e3f1cfe233fd1a1366303693a1315e33503395495db63d2ba1228e" }, "downloads": -1, "filename": "group_by_attr-1.0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "2134c1d659fea4935764398700723bb2", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 2940, "upload_time": "2015-01-28T19:05:31", "url": "https://files.pythonhosted.org/packages/0d/a2/5b7fdd6673d045c97bf764294dcca0cf2149bc6f0ba2add69ce25c80c00b/group_by_attr-1.0.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a5780b7777cccd6f14e904e973f745d2", "sha256": "ad618711b9817ae37f7abd2073749834fd15b9ac133b92939566be2ca0048d0f" }, "downloads": -1, "filename": "group-by-attr-1.0.1.tar.gz", "has_sig": false, "md5_digest": "a5780b7777cccd6f14e904e973f745d2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2113, "upload_time": "2015-01-28T19:05:29", "url": "https://files.pythonhosted.org/packages/cb/a5/f5bfd3ae4b929345f2c33c9ed777a77cb5f7299ebad0abc387fb49eab3af/group-by-attr-1.0.1.tar.gz" } ] }