Mercurial > pylearn
comparison lookup_list.py @ 71:5b699b31770a
merge
author | James Bergstra <bergstrj@iro.umontreal.ca> |
---|---|
date | Fri, 02 May 2008 18:19:35 -0400 |
parents | a5c70dc42972 |
children | 427e02ef0629 |
comparison
equal
deleted
inserted
replaced
70:76e5c0f37165 | 71:5b699b31770a |
---|---|
44 def __getitem__(self,key): | 44 def __getitem__(self,key): |
45 """ | 45 """ |
46 The key in example[key] can either be an integer to index the fields | 46 The key in example[key] can either be an integer to index the fields |
47 or the name of the field. | 47 or the name of the field. |
48 """ | 48 """ |
49 if isinstance(key,int): | 49 if isinstance(key,int) or isinstance(key,slice) or isinstance(key,list): |
50 return self._values[key] | 50 return self._values[key] |
51 else: # if not an int, key must be a name | 51 else: # if not an int, key must be a name |
52 # expecting key to be a valid field name | |
53 assert isinstance(key,str) | |
52 return self._values[self._name2index[key]] | 54 return self._values[self._name2index[key]] |
53 | 55 |
54 def __setitem__(self,key,value): | 56 def __setitem__(self,key,value): |
55 if isinstance(key,int): | 57 if isinstance(key,int): |
56 self._values[key]=value | 58 self._values[key]=value |