Back to index

salome-kernel  6.5.0
Classes | Functions | Variables
KERNEL_PY.kernel.diclookup Namespace Reference

Classes

class  Lookup

Functions

def find_key
def find_value
def TEST_getTestDictionnary
def TEST_find_value
def TEST_lookup

Variables

string __author__ = "gboulant"
string __date__ = "$21 mai 2010 18:00:23$"

Function Documentation

def KERNEL_PY.kernel.diclookup.find_key (   dic,
  val 
)
return the key of dictionary dic given the value

Definition at line 32 of file diclookup.py.

00032 
00033 def find_key(dic, val):
00034     """return the key of dictionary dic given the value"""
00035     return [k for k, v in dic.iteritems() if v == val][0]

Here is the caller graph for this function:

def KERNEL_PY.kernel.diclookup.find_value (   dic,
  key 
)
return the value of dictionary dic given the key

Definition at line 36 of file diclookup.py.

00036 
00037 def find_value(dic, key):
00038     """return the value of dictionary dic given the key"""
00039     return dic[key]

Here is the caller graph for this function:

Definition at line 83 of file diclookup.py.

00083 
00084 def TEST_find_value():
00085     symbol_dic = TEST_getTestDictionnary()
00086     print find_key(symbol_dic, 'boron')  # B
00087     print find_value(symbol_dic, 'B')    # boron
00088     print find_value(symbol_dic, 'H')    # hydrogen
00089     if find_key(symbol_dic, 'nitrogen') != 'N':
00090         return False
00091     return True

Here is the call graph for this function:

Definition at line 71 of file diclookup.py.

00071 
00072 def TEST_getTestDictionnary():
00073     # dictionary of chemical symbols
00074     symbol_dic = {
00075     'C': 'carbon',
00076     'H': 'hydrogen',
00077     'N': 'nitrogen',
00078     'Li': 'lithium',
00079     'Be': 'beryllium',
00080     'B': 'boron'
00081     }
00082     return symbol_dic

Here is the caller graph for this function:

Definition at line 92 of file diclookup.py.

00092 
00093 def TEST_lookup():
00094     symbol_dic = TEST_getTestDictionnary()
00095 
00096     name = 'lithium'
00097     symbol = 'Li'
00098     # use a dictionary as initialization argument
00099     look = Lookup(symbol_dic)
00100     print look.get_key(name)      # [Li']
00101     if look.get_key(name) != symbol:
00102         print "get "+str(look.get_key(name))+" while "+str(symbol)+" was expected"
00103         return False
00104     print look.get_value(symbol)  # lithium
00105 
00106     # use a list of pairs instead of a dictionary as initialization argument
00107     # (will be converted to a dictionary by the class internally)
00108     age_list = [['Fred', 23], ['Larry', 28], ['Ene', 23]]
00109     look2 = Lookup(age_list)
00110     print look2.get_keys(23)        # ['Ene', 'Fred']
00111     if look2.get_keys(23)[0] != 'Ene' or look2.get_keys(23)[1] != 'Fred':
00112         print "get "+str(look2.get_keys(23))+" while ['Ene', 'Fred'] was expected"
00113         return False
00114     print look2.get_value('Fred')  # 23
00115     return True

Here is the call graph for this function:


Variable Documentation

Definition at line 24 of file diclookup.py.

string KERNEL_PY.kernel.diclookup.__date__ = "$21 mai 2010 18:00:23$"

Definition at line 25 of file diclookup.py.