comparison lookup_list.py @ 137:ff6b7bfb6cdc

added function LookupList.append_lookuplist
author Frederic Bastien <bastienf@iro.umontreal.ca>
date Wed, 07 May 2008 17:01:51 -0400
parents 8fa1ef2411a0
children ad144fa72bf5
comparison
equal deleted inserted replaced
136:fa752c55aa09 137:ff6b7bfb6cdc
69 assert key not in self._name2index 69 assert key not in self._name2index
70 self._name2index[key]=len(self) 70 self._name2index[key]=len(self)
71 self._values.append(value) 71 self._values.append(value)
72 self._names.append(key) 72 self._names.append(key)
73 73
74 def append_lookuplist(self, *list):
75 for l in list:
76 for key in l.keys():
77 self.append_keyval(key,l[key])
78 del l
79
74 def __len__(self): 80 def __len__(self):
75 return len(self._values) 81 return len(self._values)
76 82
77 def __repr__(self): 83 def __repr__(self):
78 return "{%s}" % ", ".join([str(k) + "=" + repr(v) for k,v in self.items()]) 84 return "{%s}" % ", ".join([str(k) + "=" + repr(v) for k,v in self.items()])
101 def __call__(*names): 107 def __call__(*names):
102 """ 108 """
103 Return a list of values associated with the given names (which must all be keys of the lookup list). 109 Return a list of values associated with the given names (which must all be keys of the lookup list).
104 """ 110 """
105 return [self[name] for name in names] 111 return [self[name] for name in names]
112
113
114 if __name__ == '__main__':
115
116 a=LookupList(['a'],[1])
117 print a
118 b=LookupList(['b'],[2])
119 print b
120 a.append_lookuplist(b)
121 print a
122 a.append_lookuplist(b)
123 print a