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']

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.0.tar.gz (5.2 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.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aldict-1.0.0.tar.gz
  • Upload date:
  • Size: 5.2 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.0.tar.gz
Algorithm Hash digest
SHA256 9ce13e68245c268dcb13b6fbc96b196b4f54599737b5b1a4d31ac8fcb37483dc
MD5 b7fcf702868343570a35081e2cfbb559
BLAKE2b-256 b47e97fd86a982fe7f8deb3b7a78676a771e09b5bf41c34c065a7f525ee6c7a4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aldict-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.3 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 93d34d88601f45785db21e0fd784686327ad377fef3bd60e710b6e8234a86505
MD5 9e1330bc3193f917f355ed706e7801ac
BLAKE2b-256 c7aa5543a012fa8e0ee838a44a25b88950cea1a4b31666bf2f85e70599dddea8

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