Skip to main content

# Haven’t you always wanted an infinite dict?

IterDicts are similar to regular Python dicts except that they’re only populated upon demand. This gives them most of the same advantages of generators, such as the ability to operator on very large (or infinite!) datasets.

## Accessing keys that aren’t populated yet

When the get or __getitem__ methods are called, an IterDict tries to fetch a key in the normal manner. If that fails, it starts consuming the iterator it was constructed with and adding those items to itself until it finds the key (or the universe dies of heat death):

>>> d = IterDict((a, a) for a in xrange(1000000000000000))  # 1 quadrillion (US)
>>> d[10]
10
>>> list(d)
[you're going to be here a while]

## Important differences

A dict consumes its iterator at initialization, and in the case of duplicates the last value wins:

>>> d = dict([(1,1),(1,2)])
>>> d
{1: 2}
>>> del d[1]
>>> d
{}

IterDicts differ in that they stop consuming their iterators as soon as the first instance of a requested key is found:

>>> i = IterDict([(1,1), (1,2)])
>>> i
IterDict<{}, fed by <listiterator object at 0x105bab8d0>>
>>> i[1]
1
>>> i
IterDict<{1: 1}, fed by <listiterator object at 0x105bab8d0>>

For space, time, and complexity reasons, IterDicts don’t track keys that were present at one point and have been since deleted. This means that keys may reappear after deletion if the IterDict’s iterator yields them again. Continuing the previous example:

>>> del i[1]
>>> i
IterDict<{}, fed by <listiterator object at 0x105bab890>>
>>> i[1]
2
>>> i
IterDict<{1: 2}, fed by <listiterator object at 0x105bab890>>

Metadata

Release files for IterDict 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for IterDict 0.2.0
File Size Uploaded Provenance
IterDict-0.2.0.tar.gz 5.7 kB Without provenance Details

Release files / IterDict-0.2.0.tar.gz

Download URL IterDict-0.2.0.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
5c2630e562bf0627551bddd7569e491b92ea6b4512353eb7442cd1c7ca1d0469
BLAKE2b-256 checksum
How to use checksums
230eeb68c8094cf2a24067bf771b7851246b106deb599e034f192c74c834ebc5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for IterDict 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page