3 The sequential dictionary is a combination of a list and a dictionary so you can do most operations defined with lists .
4 seqdict - single value dictionary , keeps one value for one key
9 if type(List)==type({}):
12 elif List
and not Dict:
18 elif type(List)==type(Dict)==type([]):
21 for key,value
in map(
None,List,Dict):
22 self.
dict[key] = value
24 self.
list,self.
dict = List[:],Dict.copy()
27 if self.dict.has_key(key):
33 l1=self.
list[:];l1.sort()
34 l2=self.dict.keys();l2.sort()
40 if self.__class__
is seqdict:
41 return self.__class__(self.
list,self.
dict)
43 return copy.copy(self)
45 return cmp(self.
dict,other.dict)
or cmp(self.
list,other.list)
47 if type(key)==type([]):
50 newdict[i]=self.
dict[i]
51 return self.__class__(key,newdict)
54 if not self.dict.has_key(key):
61 start =
max(start,0); stop =
max(stop,0)
62 newdict = self.__class__()
63 for key
in self.
list[start:stop]:
64 newdict.dict[key]=self.
dict[key]
65 newdict.list[:]=self.
list[start:stop]
68 start =
max(start,0); stop =
max(stop,0)
70 for key
in newdict.keys():
71 if self.dict.has_key(key):
72 index = self.list.index(key)
73 delindexes.append(index)
83 for index
in delindexes:
84 key = self.
list[index]
87 for key
in self.
list[start:stop]:
89 self.
list[start:stop] = newdict.list[:]
92 start =
max(start, 0); stop =
max(stop, 0)
93 for key
in self.
list[start:stop]:
95 del self.
list[start:stop]
97 newdict = self.__class__()
98 for key,value
in self.
items()+other.items():
99 newdict.append(key,value)
102 newdict = self.__class__()
103 for key,value
in other.items()+self.
items():
104 newdict.append(key,value)
107 vallist = self.dict.values()
108 return vallist.count(value)
116 return self.__class__(liste,dict)
117 def get(self, key, failobj=None):
118 return self.dict.get(key, failobj)
119 def index(self,key):
return self.list.index(key)
122 def has_key(self,key):
return self.dict.has_key(key)
123 def keys(self):
return self.list
125 return self.__class__(
map(function,self.
items()))
128 for key
in self.
list:
129 nlist.append(self.
dict[key])
137 pos = self.list.index(key)
140 return {self.list.pop(pos):tmp}
147 self.list.remove(key)
149 def sort(self,*args):apply(self.list.sort,args)
150 def split(self,function,Ignore=None):
152 for key
in self.
list:
155 if not splitdict.has_key(skey):
156 splitdict[skey] = self.__class__()
157 splitdict[skey][key] = self.
dict[key]
160 tmp = self.__class__(
map(
lambda (x,y):(y,x),self.
items()))
161 self.
list,self.
dict = tmp.list,tmp.dict
163 for key,value
in newdict.items():
165 def slice(self,From,To=None,Step=1):
166 From = self.list.index(From)
167 if To:To = self.list.index(To)
170 List = range(From,To,Step)
171 def getitem(pos,self=self):
return self.list[pos]