Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
a3a53180
Commit
a3a53180
authored
Feb 02, 2003
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SF patch #678899: Save time and memory by using itertools in sets module.
parent
efb9625b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
19 deletions
+11
-19
Lib/sets.py
Lib/sets.py
+11
-19
No files found.
Lib/sets.py
View file @
a3a53180
...
...
@@ -57,7 +57,7 @@ what's tested is actually `z in y'.
__all__
=
[
'BaseSet'
,
'Set'
,
'ImmutableSet'
]
from
itertools
import
ifilter
class
BaseSet
(
object
):
"""Common base class for mutable and immutable sets."""
...
...
@@ -182,7 +182,7 @@ class BaseSet(object):
little
,
big
=
self
,
other
else
:
little
,
big
=
other
,
self
common
=
filter
(
big
.
_data
.
has_key
,
little
.
_data
)
common
=
ifilter
(
big
.
_data
.
has_key
,
little
)
return
self
.
__class__
(
common
)
def
intersection
(
self
,
other
):
...
...
@@ -204,12 +204,10 @@ class BaseSet(object):
value
=
True
selfdata
=
self
.
_data
otherdata
=
other
.
_data
for
elt
in
selfdata
:
if
elt
not
in
otherdata
:
data
[
elt
]
=
value
for
elt
in
otherdata
:
if
elt
not
in
selfdata
:
data
[
elt
]
=
value
for
elt
in
ifilter
(
otherdata
.
has_key
,
selfdata
,
True
):
data
[
elt
]
=
value
for
elt
in
ifilter
(
selfdata
.
has_key
,
otherdata
,
True
):
data
[
elt
]
=
value
return
result
def
symmetric_difference
(
self
,
other
):
...
...
@@ -228,11 +226,9 @@ class BaseSet(object):
return
NotImplemented
result
=
self
.
__class__
()
data
=
result
.
_data
otherdata
=
other
.
_data
value
=
True
for
elt
in
self
:
if
elt
not
in
otherdata
:
data
[
elt
]
=
value
for
elt
in
ifilter
(
other
.
_data
.
has_key
,
self
,
True
):
data
[
elt
]
=
value
return
result
def
difference
(
self
,
other
):
...
...
@@ -264,10 +260,8 @@ class BaseSet(object):
self
.
_binary_sanity_check
(
other
)
if
len
(
self
)
>
len
(
other
):
# Fast check for obvious cases
return
False
otherdata
=
other
.
_data
for
elt
in
self
:
if
elt
not
in
otherdata
:
return
False
for
elt
in
ifilter
(
other
.
_data
.
has_key
,
self
,
True
):
return
False
return
True
def
issuperset
(
self
,
other
):
...
...
@@ -275,9 +269,7 @@ class BaseSet(object):
self
.
_binary_sanity_check
(
other
)
if
len
(
self
)
<
len
(
other
):
# Fast check for obvious cases
return
False
selfdata
=
self
.
_data
for
elt
in
other
:
if
elt
not
in
selfdata
:
for
elt
in
ifilter
(
self
.
_data
.
has_key
,
other
,
True
):
return
False
return
True
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment