Changeset 388 for python/vendor/current/Lib/sets.py
- Timestamp:
- Mar 19, 2014, 11:11:30 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/vendor/current/Lib/sets.py
r2 r388 55 55 # improvements. 56 56 57 from __future__ import generators 58 try: 59 from itertools import ifilter, ifilterfalse 60 except ImportError: 61 # Code to make the module run under Py2.2 62 def ifilter(predicate, iterable): 63 if predicate is None: 64 def predicate(x): 65 return x 66 for x in iterable: 67 if predicate(x): 68 yield x 69 def ifilterfalse(predicate, iterable): 70 if predicate is None: 71 def predicate(x): 72 return x 73 for x in iterable: 74 if not predicate(x): 75 yield x 76 try: 77 True, False 78 except NameError: 79 True, False = (0==0, 0!=0) 57 from itertools import ifilter, ifilterfalse 80 58 81 59 __all__ = ['BaseSet', 'Set', 'ImmutableSet'] … … 236 214 else: 237 215 little, big = other, self 238 common = ifilter(big._data. has_key, little)216 common = ifilter(big._data.__contains__, little) 239 217 return self.__class__(common) 240 218 … … 261 239 except AttributeError: 262 240 otherdata = Set(other)._data 263 for elt in ifilterfalse(otherdata. has_key, selfdata):241 for elt in ifilterfalse(otherdata.__contains__, selfdata): 264 242 data[elt] = value 265 for elt in ifilterfalse(selfdata. has_key, otherdata):243 for elt in ifilterfalse(selfdata.__contains__, otherdata): 266 244 data[elt] = value 267 245 return result … … 288 266 otherdata = Set(other)._data 289 267 value = True 290 for elt in ifilterfalse(otherdata. has_key, self):268 for elt in ifilterfalse(otherdata.__contains__, self): 291 269 data[elt] = value 292 270 return result … … 314 292 if len(self) > len(other): # Fast check for obvious cases 315 293 return False 316 for elt in ifilterfalse(other._data. has_key, self):294 for elt in ifilterfalse(other._data.__contains__, self): 317 295 return False 318 296 return True … … 323 301 if len(self) < len(other): # Fast check for obvious cases 324 302 return False 325 for elt in ifilterfalse(self._data. has_key, other):303 for elt in ifilterfalse(self._data.__contains__, other): 326 304 return False 327 305 return True … … 338 316 self._binary_sanity_check(other) 339 317 return len(self) > len(other) and self.issuperset(other) 318 319 # We inherit object.__hash__, so we must deny this explicitly 320 __hash__ = None 340 321 341 322 # Assorted helpers … … 440 421 self._data, = data 441 422 442 # We inherit object.__hash__, so we must deny this explicitly443 __hash__ = None444 445 423 # In-place union, intersection, differences. 446 424 # Subtle: The xyz_update() functions deliberately return None, … … 504 482 if self is other: 505 483 self.clear() 506 for elt in ifilter(data. has_key, other):484 for elt in ifilter(data.__contains__, other): 507 485 del data[elt] 508 486
Note:
See TracChangeset
for help on using the changeset viewer.