Skip to main content

A dict that works with both hashable and non-hashable keys

Project description

All Purpose Dict

Note: This document is best viewed on github. Pypi's headers are all caps which presents inaccurate information


Table of Contents


What is it?

  • A dict which doesn't require hashable keys

Why create it?

  • I often have a need to store non-hashable keys in a dict. For example storing a dict as a key isn't possible with the builtin dict.

    # doesn't work
    someDict = { "key": "value" }
    anotherDict = { someDict: "anotherValue" }
    

Simple usage

from all_purpose_dict import ApDict

someDict = { "key": "value" }
anotherDict = ApDict([(someDict, "anotherValue")])

print(someDict in anotherDict) # prints True

See Also


Api

Note: This api is young and subject to change quite a bit. There also may be functionality present in the builtin dict which ApDict doesn't cover. I'm willing to add it so please just raise a github issue or PR with details.

class ApDict([a list of pairs])

  • 'pairs' may be either a list or tuple with a length of 2
  • all methods return self unless specified otherwise
  • iterates in the order of insertion
  • views are not implemented because I don't have a need for them. Instead I expose keysIterator and valuesIterator. If you need views then raise a github issue.
  • the internal methods implemented are
    • __contains__
    • __delitem__
    • __getitem__
    • __iter__
    • __len__
    • __setitem__
clear()
delete(key)
  • a function alternative to del aDict[key]
get(key, default=None) => value
  • get the value for key if key is in the dictionary, else default.
  • note: this never raises a KeyError.
has(key) => bool
  • a function alternative to key in aDict
getKeysIterator() => ApDictKeysIterator
set(key, value)
  • a function alternative to aDict[key] = val
getValuesIterator() => ApDictValuesIterator

Test

#
# you must have poetry installed
#
$ poetry shell
$ poetry install
$ python runTests.py

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

all_purpose_dict-0.2.1.tar.gz (86.7 kB view details)

Uploaded Source

Built Distribution

all_purpose_dict-0.2.1-py3-none-any.whl (99.0 kB view details)

Uploaded Python 3

File details

Details for the file all_purpose_dict-0.2.1.tar.gz.

File metadata

  • Download URL: all_purpose_dict-0.2.1.tar.gz
  • Upload date:
  • Size: 86.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.15 CPython/3.7.3 Linux/5.1.2-arch1-1-ARCH

File hashes

Hashes for all_purpose_dict-0.2.1.tar.gz
Algorithm Hash digest
SHA256 17c3bd9d18e62210f4de71d0cb848e39413e433ec162c42627eeb91256298ba5
MD5 3f783d9978c9d0f4c3e8646f5541d131
BLAKE2b-256 51f43397f6b5e2b3e9b063032f958a38a94cc04321e37ff49d73316baed14d1a

See more details on using hashes here.

File details

Details for the file all_purpose_dict-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: all_purpose_dict-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 99.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.15 CPython/3.7.3 Linux/5.1.2-arch1-1-ARCH

File hashes

Hashes for all_purpose_dict-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 64644e0bc42e40a9f68f0b7328ab16e6f9269ce50711347a6c4bd9d617de515b
MD5 d3ccf341862c3995fbcc3f5113e769ff
BLAKE2b-256 2e14bd978bd1960e10a47aff9d1be9be1f7569bb01b4033f577a4d9503c0dff3

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