{"action":"created","issue":{"url":"https://api.github.com/repos/erikrose/more-itertools/issues/66","repository_url":"https://api.github.com/repos/erikrose/more-itertools","labels_url":"https://api.github.com/repos/erikrose/more-itertools/issues/66/labels{/name}","comments_url":"https://api.github.com/repos/erikrose/more-itertools/issues/66/comments","events_url":"https://api.github.com/repos/erikrose/more-itertools/issues/66/events","html_url":"https://github.com/erikrose/more-itertools/pull/66","id":188240575,"number":66,"title":"~~Partition~~ Separate","user":{"login":"bbayles","id":1922815,"avatar_url":"https://avatars.githubusercontent.com/u/1922815?v=3","gravatar_id":"","url":"https://api.github.com/users/bbayles","html_url":"https://github.com/bbayles","followers_url":"https://api.github.com/users/bbayles/followers","following_url":"https://api.github.com/users/bbayles/following{/other_user}","gists_url":"https://api.github.com/users/bbayles/gists{/gist_id}","starred_url":"https://api.github.com/users/bbayles/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bbayles/subscriptions","organizations_url":"https://api.github.com/users/bbayles/orgs","repos_url":"https://api.github.com/users/bbayles/repos","events_url":"https://api.github.com/users/bbayles/events{/privacy}","received_events_url":"https://api.github.com/users/bbayles/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-11-09T12:53:13Z","updated_at":"2016-11-10T18:09:09Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/erikrose/more-itertools/pulls/66","html_url":"https://github.com/erikrose/more-itertools/pull/66","diff_url":"https://github.com/erikrose/more-itertools/pull/66.diff","patch_url":"https://github.com/erikrose/more-itertools/pull/66.patch"},"body":"This PR builds on the ideas in #26 and adds a `separate` function. By default it will split an input iterable into two - items that have `bool(item) == True` and items that have `bool(item) == False`. A dictionary with `True` and `False` keys is returned:\r\n\r\n```python\r\n>>> iterable = [0, '', 1, 'x', None, [1]]\r\n>>> D = separate(iterable)\r\n>>> list(D[False])\r\n[0, '', None]\r\n>>> list(D[True])\r\n[1, 'x', [1]]\r\n```\r\n\r\nYou can customize the keys of the returned dictionary as well as the function that operates on the items:\r\n\r\n```python\r\n>>> iterable = [0, 1, 2, 3, 4, 5, 6, 7, 8]\r\n>>> D = separate(iterable, keys=(0, 1, 2), fn=lambda x: x % 3)\r\n>>> list(D[0])  # Divisible by 3\r\n[0, 3, 6]\r\n>>> list(D[1])  # Remainder 1 when divided by 3\r\n[1, 4, 7]\r\n>>> list(D[2])  # Remainder 2 when divided by 3\r\n[2, 5, 8]\r\n```\r\n\r\nSince we can't know what the return values of the function will be until we run it on all of the items, you must specify up-front what you think they'll be (obviously `bool` only returns `True` and `False`). I considered having an \"other\" key in the dictionary for items that don't match any `keys`, but decided against it."},"comment":{"url":"https://api.github.com/repos/erikrose/more-itertools/issues/comments/259763697","html_url":"https://github.com/erikrose/more-itertools/pull/66#issuecomment-259763697","issue_url":"https://api.github.com/repos/erikrose/more-itertools/issues/66","id":259763697,"user":{"login":"erikrose","id":295816,"avatar_url":"https://avatars.githubusercontent.com/u/295816?v=3","gravatar_id":"","url":"https://api.github.com/users/erikrose","html_url":"https://github.com/erikrose","followers_url":"https://api.github.com/users/erikrose/followers","following_url":"https://api.github.com/users/erikrose/following{/other_user}","gists_url":"https://api.github.com/users/erikrose/gists{/gist_id}","starred_url":"https://api.github.com/users/erikrose/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/erikrose/subscriptions","organizations_url":"https://api.github.com/users/erikrose/orgs","repos_url":"https://api.github.com/users/erikrose/repos","events_url":"https://api.github.com/users/erikrose/events{/privacy}","received_events_url":"https://api.github.com/users/erikrose/received_events","type":"User","site_admin":false},"created_at":"2016-11-10T18:09:09Z","updated_at":"2016-11-10T18:09:09Z","body":"Yes, it still requires buffering the whole thing, but the call no longer requires `keys`. There might even be situations in which `keys` could not be predetermined.\n\n"}}
{"actor":{"display_login":"erikrose"}}