Share and Money Management  0.16
Public Member Functions | Public Attributes | List of all members
gui.helper.ReverseDict Class Reference

A dictionary which can lookup values by key, and keys by value. More...

Public Member Functions

def __init__
 Initialise the data structures.
def __setitem__
 Set a new key / value pair.
def __delitem__
 Remove a key / value pair out of both dictionaries.

Public Attributes

 reverse
 Dictionary to store the reverse data.

Detailed Description

A dictionary which can lookup values by key, and keys by value.

All values and keys must be hashable, and unique.

Example:
>>> a = gui.helper.ReverseDict(((1,2),(3,4)))
>>> print a[1]
2
>>> print a.reverse[2]
1
>>> a["123"] = 67
>>> print a["123"]
67
>>> print a.reverse[67]
123
Idea:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/415903

Constructor & Destructor Documentation

def gui.helper.ReverseDict.__init__ (   self,
  args,
  kw 
)

Initialise the data structures.

Member Function Documentation

def gui.helper.ReverseDict.__delitem__ (   self,
  key 
)

Remove a key / value pair out of both dictionaries.

References gui.helper.ReverseDict.reverse.

def gui.helper.ReverseDict.__setitem__ (   self,
  key,
  value 
)

Set a new key / value pair.

Already existing keys or values will be removed before adding new one.

References gui.helper.ReverseDict.reverse.

Member Data Documentation

gui.helper.ReverseDict.reverse

Dictionary to store the reverse data.

The key / value pairs are reverse stored. This means the value is used as key and the origin key is stored as value in this dictionary. Thereby an fast reverse lookup to get the corresponding key of a given value.

Referenced by gui.helper.ReverseDict.__delitem__(), and gui.helper.ReverseDict.__setitem__().


The documentation for this class was generated from the following file: