Skip to main content

A dict that can use unhashable keys

Project description

DictAnyKey: Python Dictionary That Can Use Any Key

PyPI Latest Release

What is it?

DictAnyKey is a Python package that provides a dictionary like object that can use unhashable keys (such as list and dict) as well as hashable keys.

Main Features

Here are just a few of the things that DictAnyKey does well:

  • Use unhashable objects as keys, such as list and dict but with slower retrieval.
  • Stores and retrieves values using hashable keys at same speed as built in dict.
  • Maintains order of insertion just like built in dict.

Where to get it

The source code is currently hosted on GitHub at: https://github.com/eddiethedean/dictanykey

# PyPI
pip install dictanykey

Dependencies

  • [python >= 3.6]

Example

from dictanykey import DictAnyKey

# Start with empty DictAnyKey
d = DictAnyKey()

# Add value with unhashable key
d[[1, 2]] = 'one two'

# Add value with hashable key
d[1] = 'one'

# Get value with key
d[[1, 2]] -> 'one two'

str(d) -> '{[1, 2]: "one two", 1: "one"}'

# Delete items with del
del d[[1, 2]]

# Start with filled in DictAnyKey, use list of tuples
d = DictAnyDict([([2, 2], 'two two'), (2, 'two')])

str(d) -> '{[2, 2]: "two two", 2: "two"}'

# Has keys, values, and items methods (all results are iterable)
d.keys() -> DictKeys([[2, 2], 2])
d.values() -> DictValues('two two', 'two')
d.items() -> DictItems([([2, 2], 'two two'), (2, 'two')])

# check for key membership
[2, 2] in d -> True
[3, 4] in d -> False

# Has get method with default parameter
d.get(5, default='Missing') -> 'Missing'
d.get([2, 2], default='Missing') -> 'two two'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dictanykey-0.1.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

dictanykey-0.1.0-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file dictanykey-0.1.0.tar.gz.

File metadata

  • Download URL: dictanykey-0.1.0.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.16

File hashes

Hashes for dictanykey-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e607f976044129a038435bd3286a93db453eb222e189f31a2fb0864799b45475
MD5 9418ce66d273caad19d64af72434ec3e
BLAKE2b-256 93adbd4c892aa5457a3ed7e89cb25a0e6bcefc28033684f6afa507aaffb7a80e

See more details on using hashes here.

File details

Details for the file dictanykey-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: dictanykey-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.16

File hashes

Hashes for dictanykey-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7844f866f2f35f05c52bedde6c4c747333354677d0b8d60f1d33064ce875e686
MD5 6d307e9fdd59e7c005b589f8d48a7598
BLAKE2b-256 db15ce5c9647d094d8ba0871e53411a8c15b46c335d687a430809b1a1382f6fa

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page