Mercurial > pylearn
comparison lookup_list.py @ 142:ad144fa72bf5
Automated merge with ssh://p-omega1@lgcm.iro.umontreal.ca/tlearn
author | Frederic Bastien <bastienf@iro.umontreal.ca> |
---|---|
date | Mon, 12 May 2008 14:15:16 -0400 |
parents | 3f4e5c9bdc5e ff6b7bfb6cdc |
children | 4803cb76e26b |
comparison
equal
deleted
inserted
replaced
134:3f4e5c9bdc5e | 142:ad144fa72bf5 |
---|---|
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__(self,*names): | 107 def __call__(self,*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 |