A collection of convenient Python data structures.
A dictionary that always sorts the items in its tuple keys.
Parameters: | items – an iterable of pairs of keys and values; keys should be tuples |
---|
A dictionary that has sets as values, and allows looking up the key of any item that is in at least one set within the values.
Parameters: | items – an iterable of pairs of keys and values; values should be set instances |
---|
Adds a item to the set belonging to the key.
Raises a KeyError if the key does not exist.
Parameters: |
|
---|
Return a shallow copy.
Returns a set of all keys whose set values the item is present in.
Raises a KeyError if the item is not present in any of the values.
Parameters: | item – an item in one of the value sets |
---|
Performs a reverse-lookup to see if an item exists among the sets in the dictionary’s values.
Returns True if the item is among the values, or False if the item is not.
Parameters: | item – an item that may be among the ``set``s in the main dictionary’s values |
---|
See if an item in the values of the dictionary has a reverse mapping to an item.
Raises a KeyError if the item is not present in any of the values.
Returns True if the item has a reverse mapping to the key, or False if the item has no reverse mapping to the key.
Parameters: |
|
---|
Removes an item from the set belonging to the key.
Raises a KeyError if the key does not exist, or if the item is not present in the set belonging to the key.
Parameters: |
|
---|
Removes an item from all set values in the main dictionary to which it belongs.
Raises a KeyError if the item is not present in any of the values.
Parameters: | item – an item to be removed from all sets of values |
---|
Returns a list of tuples for reverse key and value pairs.
Yields individual key-value pairs for the reversed items.
Returns an iterable of the keys of the reverse dictionary.
These items are the items in the value sets of the main dictionary.
Returns an iterable of the values of the reverse dictionary.
These values are sets of the keys in the main dictionary.
Returns a list of the keys of the reverse dictionary.
These items are the items in the value sets of the main dictionary.
Returns a list of the values of the reverse dictionary.
These values are sets of the keys in the main dictionary.
Given a dictionary with lists as values, samples a given number of sub-elements uniformly at random.
Consumes less memory than dict_list_random_sample().
Parameters: |
|
---|---|
Returns: | a dictionary with the given number of sub-elements |
Given a dictionary with lists as values, samples a given number of sub-elements uniformly at random.
Consumes less memory than dict_list_random_sample() for large dictionaries.
Parameters: |
|
---|---|
Returns: | a dictionary with the given number of sub-elements |