[pypy-svn] r77757 - in pypy/branch/fast-forward/lib_pypy: . pypy_test
afa at codespeak.net
afa at codespeak.net
Sun Oct 10 13:36:09 CEST 2010
Author: afa
Date: Sun Oct 10 13:36:08 2010
New Revision: 77757
Modified:
pypy/branch/fast-forward/lib_pypy/_collections.py
pypy/branch/fast-forward/lib_pypy/pypy_test/test_collections.py
Log:
Add deque.count()
Modified: pypy/branch/fast-forward/lib_pypy/_collections.py
==============================================================================
--- pypy/branch/fast-forward/lib_pypy/_collections.py (original)
+++ pypy/branch/fast-forward/lib_pypy/_collections.py Sun Oct 10 13:36:08 2010
@@ -125,6 +125,13 @@
self.leftndx = 0
return x
+ def count(self, value):
+ c = 0
+ for i in range(len(self)):
+ if self[i] == value:
+ c += 1
+ return c
+
def remove(self, value):
# Need to be defensive for mutating comparisons
for i in range(len(self)):
Modified: pypy/branch/fast-forward/lib_pypy/pypy_test/test_collections.py
==============================================================================
--- pypy/branch/fast-forward/lib_pypy/pypy_test/test_collections.py (original)
+++ pypy/branch/fast-forward/lib_pypy/pypy_test/test_collections.py Sun Oct 10 13:36:08 2010
@@ -29,6 +29,11 @@
d3 = copy.copy(d)
assert repr(d3) == "deque([2, 3, 4], maxlen=3)"
+def test_deque_count():
+ d = collections.deque([1, 2, 2, 3, 2])
+ assert d.count(2) == 3
+ assert d.count(4) == 0
+
class SubclassWithKwargs(collections.deque):
def __init__(self, newarg=1):
collections.deque.__init__(self)
More information about the Pypy-commit
mailing list