Skip to main content

Multi-key dictionary, supports adding and manipulating key-aliases pointing to shared values

Project description

Alter Ego


Aldict

tests Python 3.x PyPI License

Multi-key dictionary, supports adding and manipulating key-aliases pointing to shared values


How to use

  • add_alias
    (pass key as first parameter and alias(es) as variadic params)
ad = AliasDict({"a": 1, "b": 2})
ad.add_alias("a", "aa")
ad.add_alias("b", "bb", "Bbb")
assert ad["a"] == ad["aa"] == 1
assert ad["b"] == ad["bb"] == ad["Bbb"] == 2
  • remove_alias
    (pass alias(es) to be removed as variadic parameters)
ad.remove_alias("aa")
ad.remove_alias("bb", "Bbb")
assert len(ad.aliases()) == 0
  • clear_aliases
    (remove all aliases at once)
ad.clear_aliases()
assert len(ad.aliases()) == 0
  • update alias
    (point alias to different key)
ad = AliasDict({"a": 1, "b": 2})
ad.add_alias("a", "ab")
assert list(ad.items()) == [('a', 1), ('b', 2), ('ab', 1)]

ad.add_alias("b", "ab")
assert list(ad.items()) == [('a', 1), ('b', 2), ('ab', 2)]
  • read all aliases
ad = AliasDict({"a": 1, "b": 2})
ad.add_alias("a", "aa")
ad.add_alias("b", "bb", "B")
ad.add_alias("a", "ab", "A")
assert list(ad.aliases()) == ['aa', 'bb', 'B', 'ab', 'A']
  • aliased_keys
    (read keys with corresponding alias(es))
assert dict(ad.aliased_keys()) == {'a': ['aa', 'ab', 'A'], 'b': ['bb', 'B']}
  • read dictviews
    (dict.keys() and dict.items() include aliased versions)
ad = AliasDict({"x": 10, "y": 20})
ad.add_alias("x", "Xx")
ad.add_alias("y", "Yy", "xyz")

ad.keys()
ad.values()
ad.items()
dict_keys(['x', 'y', 'Xx', 'Yy', 'xyz'])
dict_values([10, 20])
dict_items([('x', 10), ('y', 20), ('Xx', 10), ('Yy', 20), ('xyz', 20)])
  • remove key and aliases
ad.pop("y")
assert list(ad.items()) == [('x', 10), ('Xx', 10)]
  • origin_keys
    (get original keys only)
assert list(ad.origin_keys()) == ['x', 'y']
  • origin_len
    (get original dict length without aliases)
ad = AliasDict({"a": 1, "b": 2})
ad.add_alias("a", "aa")
assert list(ad.keys()) == ["a", "b", "aa"]
assert len(ad) == 3
assert ad.origin_len() == 2

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

aldict-1.0.1.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aldict-1.0.1-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file aldict-1.0.1.tar.gz.

File metadata

  • Download URL: aldict-1.0.1.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.0

File hashes

Hashes for aldict-1.0.1.tar.gz
Algorithm Hash digest
SHA256 944e8cdd4f6b437e72943dc36e7b3676674138bcb258b4a125a898fb1fb3670f
MD5 bc9f0dc6daea39c5fd55ae4772369d0e
BLAKE2b-256 eea0f0c90601a8e35541c1b28c30f83f8198e77a94c61531dc7c8cb79dff5d7f

See more details on using hashes here.

File details

Details for the file aldict-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: aldict-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.0

File hashes

Hashes for aldict-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 932081ea7dcd0f5ad7f26c5f77cc77f4978fddd8497fb26e82bb949e22386b67
MD5 80aa000296b0125ed1d71a241a6be40e
BLAKE2b-256 7c4b9290cbddfa9f1e3097c2dc8e8d7a358550eabea79e861246df8143aeee28

See more details on using hashes here.

Supported by

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