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) => value
  • a function alternative to val = aDict[key]
has(key) => bool
  • a function alternative to key in aDict
keysIterator() => ApDictKeysIterator
set(key, value)
  • a function alternative to aDict[key] = val
valuesIterator() => 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.1.2.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

all_purpose_dict-0.1.2-py3-none-any.whl (28.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: all_purpose_dict-0.1.2.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.11 CPython/3.7.1 Linux/4.20.3-arch1-1-ARCH

File hashes

Hashes for all_purpose_dict-0.1.2.tar.gz
Algorithm Hash digest
SHA256 db6b7e613b0611a8d2d0bfa1e128b4b1a4911a248318d0c3c1879a014674512e
MD5 ef85cf22084c8a08f719539969e89e0e
BLAKE2b-256 bf299779eb8a64715d4a8574eb694bb0ffb2be4fd27808802bcb7b7ce2e27c46

See more details on using hashes here.

File details

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

File metadata

  • Download URL: all_purpose_dict-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 28.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.11 CPython/3.7.1 Linux/4.20.3-arch1-1-ARCH

File hashes

Hashes for all_purpose_dict-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 711c9188ea4716ff18cf27eec00b47c502bf53fc304831a0c3f59a44bf9eb00e
MD5 7f9b84560b59316c8363a240228781f4
BLAKE2b-256 8966a432cb81ae453845702ff0f1d279864747d6aeb867007e7fd6ab98cd8dd7

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