Salome HOME
Merge branch 'eap/23514'
[modules/kernel.git] / src / KERNEL_PY / kernel / diclookup.py
index 9bbbe2f84158f1771cc5c99eed09a62aea5800fe..1ec0eab1750e08177fa494d76245c734086a4a53 100644 (file)
@@ -1,5 +1,5 @@
 # -*- coding: iso-8859-1 -*-
-# Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+# Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 #
 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
 
+## \defgroup diclookup diclookup
+#  \{ 
+#  \details Smart dictionary with key/value lookup
+#  \}
+
 __author__="gboulant"
 __date__ ="$21 mai 2010 18:00:23$"
 
@@ -29,26 +34,38 @@ __date__ ="$21 mai 2010 18:00:23$"
 # using named functions or a class
 # tested with Python25   by Ene Uran    01/19/2008
 
+## return the key of dictionary dic given the value
+#  \ingroup diclookup
 def find_key(dic, val):
     """return the key of dictionary dic given the value"""
     return [k for k, v in dic.iteritems() if v == val][0]
 
+## return the value of dictionary dic given the key
+#  \ingroup diclookup
 def find_value(dic, key):
     """return the value of dictionary dic given the key"""
     return dic[key]
 
+## a dictionary which can lookup value by key, or keys by value
+#  \ingroup diclookup
 class Lookup(dict):
     """
     a dictionary which can lookup value by key, or keys by value
     """
-    def __init__(self, items=[]):
+    ## items can be a list of pair_lists or a dictionary
+    def __init__(self, items=None):
         """items can be a list of pair_lists or a dictionary"""
+       if items is None:
+           items = []
         dict.__init__(self, items)
 
+    ## find the key(s) as a list given a value
     def get_keys(self, value):
         """find the key(s) as a list given a value"""
         return [item[0] for item in self.items() if item[1] == value]
 
+    ## find the key associated to the given a value. If several keys exist,
+    #  only the first is given. To get the whole list, use get_keys instead.
     def get_key(self, value):
         """
         find the key associated to the given a value. If several keys exist,
@@ -59,6 +76,7 @@ class Lookup(dict):
             return None
         return list[0]
 
+    ## find the value given a key
     def get_value(self, key):
         """find the value given a key"""
         return self[key]