Mercurial > pylearn
comparison lookup_list.py @ 45:a5c70dc42972
Test functions for dataset.py
author | bengioy@grenat.iro.umontreal.ca |
---|---|
date | Tue, 29 Apr 2008 11:25:36 -0400 |
parents | b6b36f65664f |
children | 427e02ef0629 |
comparison
equal
deleted
inserted
replaced
44:5a85fda9b19b | 45:a5c70dc42972 |
---|---|
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 |