Skip to main content

Mapping-like objects with unordered multisets as keys.

Project description

multiset-key-dict

This small library implements a mapping-like object whose keys are taken to be unordered multisets (Counters, bags), regardless of the type of the actual indexes used.

Example

Create a MultisetKeyDict and insert an element for the set {1, 3, 5}.

from multiset_key_dict import MultisetKeyDict
mskd = MultisetKeyDict()
mskd[[1, 3, 5]] = 19

Access the element just added.

# In a different order.
print(mskd[[3, 5, 1]]) # 19
# With a different type of collection.
print(mskd[{3, 5, 1}]) # 19

__iter__ iterates over items in the MultisetKeyDict, viewed as frozensets (i.e., not accounting for multiplicity).

# Add more data.
mskd[[1]] = 9
mskd[[5, 6]] = 12
print(list(mskd)) # [(frozenset({1, 3, 5}), 19), (frozenset({1}), 9), (frozenset({5, 6}), 12)]

To iterate over key-value pairs where the keys are the FrozenMultiset objects that act as the true keys in the structure, use multiset_iter or items methods instead.

mskd[[1, 1]] = 90
print(list(mskd))
# [(frozenset({1, 3, 5}), 19), (frozenset({1}), 9), (frozenset({5, 6}), 12),
# (frozenset({1}), 90)]

print(list(mskd.multiset_iter()))
# [(FrozenMultiset({(3, 1), (1, 1), (5, 1)}), 19), 
#  (FrozenMultiset({(1, 1)}), 9),
#  (FrozenMultiset({(6, 1), (5, 1)}), 12),
#  (FrozenMultiset({(1, 2)}), 90)]

To get the keys as frozenset objects, use set_keys. To get the keys as FrozenMultiset objects, use multiset_keys or keys.

It's sometimes useful to get the set of elements of the keys. For that, you can use the key_elements method.

print(mskd.key_elements()) # frozenset({1, 3, 5, 6})

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

multiset_key_dict-0.2.3.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

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

multiset_key_dict-0.2.3-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file multiset_key_dict-0.2.3.tar.gz.

File metadata

  • Download URL: multiset_key_dict-0.2.3.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for multiset_key_dict-0.2.3.tar.gz
Algorithm Hash digest
SHA256 c80a9d25f12a34e5ef87bd49ba77501985cdf50a066378686a6f97a425027834
MD5 cad88c9f93817156fee6a89516501366
BLAKE2b-256 309e3580d5f15c358c84996e3b6eae5872430c399dca8f323b92c3f8698c4af5

See more details on using hashes here.

Provenance

The following attestation bundles were made for multiset_key_dict-0.2.3.tar.gz:

Publisher: package.yml on actapia/multiset-key-dict

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file multiset_key_dict-0.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for multiset_key_dict-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 cfa0cf111b03d38a23b554ae75aed822611510a3275c8766240e264973dfcf2c
MD5 f5c96a5abf8dcc004dec64204dccbb71
BLAKE2b-256 27217c604dd1fb1070795a4c1c160073ba15fb635f32dc79d5423b106d878980

See more details on using hashes here.

Provenance

The following attestation bundles were made for multiset_key_dict-0.2.3-py3-none-any.whl:

Publisher: package.yml on actapia/multiset-key-dict

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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