mirror of
https://github.com/python/cpython.git
synced 2025-10-17 20:28:43 +00:00
C Code:
* Removed the ifilter flag wart by splitting it into two simpler functions. * Fixed comment tabbing in C code. * Factored module start-up code into a loop. Documentation: * Re-wrote introduction. * Addede examples for quantifiers. * Simplified python equivalent for islice(). * Documented split of ifilter(). Sets.py: * Replace old ifilter() usage with new.
This commit is contained in:
parent
cb3319f61e
commit
60eca9331a
4 changed files with 354 additions and 193 deletions
12
Lib/sets.py
12
Lib/sets.py
|
@ -57,7 +57,7 @@ what's tested is actually `z in y'.
|
|||
|
||||
|
||||
__all__ = ['BaseSet', 'Set', 'ImmutableSet']
|
||||
from itertools import ifilter
|
||||
from itertools import ifilter, ifilterfalse
|
||||
|
||||
class BaseSet(object):
|
||||
"""Common base class for mutable and immutable sets."""
|
||||
|
@ -204,9 +204,9 @@ class BaseSet(object):
|
|||
value = True
|
||||
selfdata = self._data
|
||||
otherdata = other._data
|
||||
for elt in ifilter(otherdata.has_key, selfdata, True):
|
||||
for elt in ifilterfalse(otherdata.has_key, selfdata):
|
||||
data[elt] = value
|
||||
for elt in ifilter(selfdata.has_key, otherdata, True):
|
||||
for elt in ifilterfalse(selfdata.has_key, otherdata):
|
||||
data[elt] = value
|
||||
return result
|
||||
|
||||
|
@ -227,7 +227,7 @@ class BaseSet(object):
|
|||
result = self.__class__()
|
||||
data = result._data
|
||||
value = True
|
||||
for elt in ifilter(other._data.has_key, self, True):
|
||||
for elt in ifilterfalse(other._data.has_key, self):
|
||||
data[elt] = value
|
||||
return result
|
||||
|
||||
|
@ -260,7 +260,7 @@ class BaseSet(object):
|
|||
self._binary_sanity_check(other)
|
||||
if len(self) > len(other): # Fast check for obvious cases
|
||||
return False
|
||||
for elt in ifilter(other._data.has_key, self, True):
|
||||
for elt in ifilterfalse(other._data.has_key, self):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
@ -269,7 +269,7 @@ class BaseSet(object):
|
|||
self._binary_sanity_check(other)
|
||||
if len(self) < len(other): # Fast check for obvious cases
|
||||
return False
|
||||
for elt in ifilter(self._data.has_key, other, True):
|
||||
for elt in ifilterfalse(self._data.has_key, other):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue