pseudo.py (ae54856b) | pseudo.py (7d9fa7c3) |
---|---|
1#************************************************************** 2# 3# Licensed to the Apache Software Foundation (ASF) under one 4# or more contributor license agreements. See the NOTICE file 5# distributed with this work for additional information 6# regarding copyright ownership. The ASF licenses this file 7# to you under the Apache License, Version 2.0 (the 8# "License"); you may not use this file except in compliance --- 24 unchanged lines hidden (view full) --- 33 34 def __or__(self, other): 35 tmplist = [] 36 if self._list != None and other != None: 37 tmplist.extend(self._list) 38 tmplist.extend(other) 39 return PseudoSet(self._remove_dupes(tmplist)) 40 else: | 1#************************************************************** 2# 3# Licensed to the Apache Software Foundation (ASF) under one 4# or more contributor license agreements. See the NOTICE file 5# distributed with this work for additional information 6# regarding copyright ownership. The ASF licenses this file 7# to you under the Apache License, Version 2.0 (the 8# "License"); you may not use this file except in compliance --- 24 unchanged lines hidden (view full) --- 33 34 def __or__(self, other): 35 tmplist = [] 36 if self._list != None and other != None: 37 tmplist.extend(self._list) 38 tmplist.extend(other) 39 return PseudoSet(self._remove_dupes(tmplist)) 40 else: |
41 print "__or__(None)" | 41 print("__or__(None)") |
42 43 def __sub__(self,other): 44 tmplist = [] 45 if self._list != None and other != None: 46 tmplist.extend(self._list) 47 [tmplist.remove(key) for key in other if key in tmplist] 48 else: | 42 43 def __sub__(self,other): 44 tmplist = [] 45 if self._list != None and other != None: 46 tmplist.extend(self._list) 47 [tmplist.remove(key) for key in other if key in tmplist] 48 else: |
49 print "__sub__(none)" | 49 print("__sub__(none)") |
50 return PseudoSet(tmplist) 51 52 def __and__(self, other): 53 tmplist = [] 54 if other != None and self._list != None: 55 [tmplist.append(key) for key in self._list if key in other] 56 return PseudoSet(tmplist) 57 else: | 50 return PseudoSet(tmplist) 51 52 def __and__(self, other): 53 tmplist = [] 54 if other != None and self._list != None: 55 [tmplist.append(key) for key in self._list if key in other] 56 return PseudoSet(tmplist) 57 else: |
58 print "__and__(None)" | 58 print("__and__(None)") |
59 60 def __iter__(self): 61 return self._list.__iter__() 62 63 def __items__(self): | 59 60 def __iter__(self): 61 return self._list.__iter__() 62 63 def __items__(self): |
64 return self._list.items() | 64 return list(self._list.items()) |
65 66 def __keys__(self): 67 return keys(self._list) 68 69 def _remove_dupes(self, list): 70 tmpdict = {} 71 for key in list: 72 tmpdict[key] = 1 | 65 66 def __keys__(self): 67 return keys(self._list) 68 69 def _remove_dupes(self, list): 70 tmpdict = {} 71 for key in list: 72 tmpdict[key] = 1 |
73 return tmpdict.keys() | 73 return list(tmpdict.keys()) |
74 75# incomplete OrderedDict() class implementation 76class PseudoOrderedDict(dict): 77 _keylist = [] 78 _valuelist = [] 79 80 def __init__(self, defaults={}): 81 dict.__init__(self) | 74 75# incomplete OrderedDict() class implementation 76class PseudoOrderedDict(dict): 77 _keylist = [] 78 _valuelist = [] 79 80 def __init__(self, defaults={}): 81 dict.__init__(self) |
82 for n,v in defaults.items(): | 82 for n,v in list(defaults.items()): |
83 self[n] = v 84 85 def __setitem__(self, key, value): 86 self._keylist.append(key) 87 self._valuelist.append(value) 88 return dict.__setitem__(self, key, value) 89 90 def __delattr__(self, key): --- 9 unchanged lines hidden (view full) --- 100 def __iter__(self): 101 raise NotImplementedError("__iter__") 102 103 def __iterkeys__(self): 104 return self._keylist 105 106 def iteritems(self): 107 #return self._valuelist | 83 self[n] = v 84 85 def __setitem__(self, key, value): 86 self._keylist.append(key) 87 self._valuelist.append(value) 88 return dict.__setitem__(self, key, value) 89 90 def __delattr__(self, key): --- 9 unchanged lines hidden (view full) --- 100 def __iter__(self): 101 raise NotImplementedError("__iter__") 102 103 def __iterkeys__(self): 104 return self._keylist 105 106 def iteritems(self): 107 #return self._valuelist |
108 return zip(self._keylist, self._valuelist) | 108 return list(zip(self._keylist, self._valuelist)) |
109 110 def items(self): | 109 110 def items(self): |
111 return zip(self._keylist,self._valuelist) | 111 return list(zip(self._keylist,self._valuelist)) |
112 113 def __keys__(self): 114 return self._keylist 115 116 def keys(self): 117 return self._keylist 118 119 def __keysattr__(self): --- 15 unchanged lines hidden (view full) --- 135 136 list1.append("a") 137 list1.append("b") 138 list1.append("d") 139 list1.append("e") 140 list1.append("e") 141 142 if "a" in list: | 112 113 def __keys__(self): 114 return self._keylist 115 116 def keys(self): 117 return self._keylist 118 119 def __keysattr__(self): --- 15 unchanged lines hidden (view full) --- 135 136 list1.append("a") 137 list1.append("b") 138 list1.append("d") 139 list1.append("e") 140 list1.append("e") 141 142 if "a" in list: |
143 print "YEAH!" | 143 print("YEAH!") |
144 145 a = PseudoSet(list) 146 b = PseudoSet(list1) 147 | 144 145 a = PseudoSet(list) 146 b = PseudoSet(list1) 147 |
148 print "a="+str(a) 149 print "b="+str(b) 150 print "a|b=" + str(a|b) 151 print "a="+str(a) 152 print "b="+str(b) 153 print "a&b=" + str(a&b) 154 print "a="+str(a) 155 print "b="+str(b) 156 print "a-b" + str(a-b) | 148 print("a="+str(a)) 149 print("b="+str(b)) 150 print("a|b=" + str(a|b)) 151 print("a="+str(a)) 152 print("b="+str(b)) 153 print("a&b=" + str(a&b)) 154 print("a="+str(a)) 155 print("b="+str(b)) 156 print("a-b" + str(a-b)) |
157 158 for key in a: | 157 158 for key in a: |
159 print key | 159 print(key) |
160 161def _testdriver_dict(): 162 d = PseudoOrderedDict() 163 d["a"] = 1 164 d["b"] = 2 165 d["c"] = 3 166 d["d"] = 4 167 d["e"] = 5 168 d["f"] = 6 169 | 160 161def _testdriver_dict(): 162 d = PseudoOrderedDict() 163 d["a"] = 1 164 d["b"] = 2 165 d["c"] = 3 166 d["d"] = 4 167 d["e"] = 5 168 d["f"] = 6 169 |
170 print "a="+str(d["a"]) 171 print "e="+str(d["e"]) 172 for key,value in d.iteritems(): 173 print "d["+key+"]="+str(d[key]) 174 print "key="+str(key)+" value="+str(value) | 170 print("a="+str(d["a"])) 171 print("e="+str(d["e"])) 172 for key,value in d.items(): 173 print("d["+key+"]="+str(d[key])) 174 print("key="+str(key)+" value="+str(value)) |
175 | 175 |
176 print "keys="+str(d.keys()) | 176 print("keys="+str(list(d.keys()))) |
177 178#_testdriver_dict() | 177 178#_testdriver_dict() |