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
dd01f8f3
Commit
dd01f8f3
authored
Jan 22, 2009
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update comments and add an optimized path for Counter.update().
parent
94adc8e4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
3 deletions
+5
-3
Lib/collections.py
Lib/collections.py
+5
-3
No files found.
Lib/collections.py
View file @
dd01f8f3
...
...
@@ -255,8 +255,11 @@ class Counter(dict):
if
iterable
is
not
None
:
if
isinstance
(
iterable
,
Mapping
):
for
elem
,
count
in
iterable
.
items
():
self
[
elem
]
+=
count
if
self
:
for
elem
,
count
in
iterable
.
items
():
self
[
elem
]
+=
count
else
:
dict
.
update
(
self
,
iterable
)
# fast path when counter is empty
else
:
for
elem
in
iterable
:
self
[
elem
]
+=
1
...
...
@@ -282,7 +285,6 @@ class Counter(dict):
# Knuth TAOCP Volume II section 4.6.3 exercise 19
# and at http://en.wikipedia.org/wiki/Multiset
#
# Results are undefined when inputs contain negative counts.
# Outputs guaranteed to only include positive counts.
#
# To strip negative and zero counts, add-in an empty counter:
...
...
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