{"id":25640527,"url":"https://github.com/kstrauser/iterdict","last_synced_at":"2025-07-16T02:32:41.194Z","repository":{"id":3269596,"uuid":"4308883","full_name":"kstrauser/iterdict","owner":"kstrauser","description":"Lazy-populated dict that retrieves keys from an iterator as they're accessed","archived":false,"fork":false,"pushed_at":"2012-05-13T23:22:41.000Z","size":122,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-15T19:00:00.741Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kstrauser.png","metadata":{"files":{"readme":"README.markdown","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-05-12T18:55:02.000Z","updated_at":"2013-10-06T19:31:01.000Z","dependencies_parsed_at":"2022-08-27T04:32:55.434Z","dependency_job_id":null,"html_url":"https://github.com/kstrauser/iterdict","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kstrauser%2Fiterdict","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kstrauser%2Fiterdict/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kstrauser%2Fiterdict/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kstrauser%2Fiterdict/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kstrauser","download_url":"https://codeload.github.com/kstrauser/iterdict/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240271524,"owners_count":19774859,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-23T04:40:07.993Z","updated_at":"2025-02-23T04:40:09.032Z","avatar_url":"https://github.com/kstrauser.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Haven't you always wanted an infinite dict?\n\nIterDicts are similar to regular Python dicts except that they're only\npopulated upon demand. This gives them most of the same advantages of\ngenerators, such as the ability to operator on very large (or infinite!)\ndatasets.\n\n## Accessing keys that aren't populated yet\n\nWhen the `get` or `__getitem__` methods are called, an IterDict tries to\nfetch a key in the normal manner. If that fails, it starts consuming the\niterator it was constructed with and adding those items to itself until\nit finds the key (or the universe dies of heat death):\n\n\t\u003e\u003e\u003e d = IterDict((a, a) for a in xrange(1000000000000000))  # 1 quadrillion (US)\n\t\u003e\u003e\u003e d[10]\n\t10\n\n    \u003e\u003e\u003e list(d)\n    [you're going to be here a while]\n\n## Important differences\n\nA dict consumes its iterator at initialization, and in the case of duplicates\nthe last value wins:\n\n    \u003e\u003e\u003e d = dict([(1,1),(1,2)])\n    \u003e\u003e\u003e d\n    {1: 2}\n    \u003e\u003e\u003e del d[1]\n    \u003e\u003e\u003e d\n    {}\n\nIterDicts differ in that they stop consuming their iterators as soon as the\nfirst instance of a requested key is found:\n\n    \u003e\u003e\u003e i = IterDict([(1,1), (1,2)])\n    \u003e\u003e\u003e i\n    IterDict\u003c{}, fed by \u003clistiterator object at 0x105bab8d0\u003e\u003e\n    \u003e\u003e\u003e i[1]\n    1\n    \u003e\u003e\u003e i\n    IterDict\u003c{1: 1}, fed by \u003clistiterator object at 0x105bab8d0\u003e\u003e\n\nFor space, time, and complexity reasons, IterDicts don't track keys that were\npresent at one point and have been since deleted. This means that keys may\nreappear after deletion if the IterDict's iterator yields them again.\nContinuing the previous example:\n\n    \u003e\u003e\u003e del i[1]\n    \u003e\u003e\u003e i\n    IterDict\u003c{}, fed by \u003clistiterator object at 0x105bab890\u003e\u003e\n    \u003e\u003e\u003e i[1]\n    2\n    \u003e\u003e\u003e i\n    IterDict\u003c{1: 2}, fed by \u003clistiterator object at 0x105bab890\u003e\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkstrauser%2Fiterdict","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkstrauser%2Fiterdict","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkstrauser%2Fiterdict/lists"}