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...

Inheritance diagram for gui.helper.ReverseDict:

Public Member Functions

def __init__ (self, args, kw)
 Initialise the data structures. More...
 
def __setitem__ (self, key, value)
 Set a new key / value pair. More...
 
def __delitem__ (self, key)
 Remove a key / value pair out of both dictionaries. More...
 

Public Attributes

 reverse
 Dictionary to store the reverse data. More...
 

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

◆ __init__()

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

Initialise the data structures.

Member Function Documentation

◆ __delitem__()

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

Remove a key / value pair out of both dictionaries.

References gui.helper.ReverseDict.reverse.

◆ __setitem__()

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

◆ reverse

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: