Skip to content

Commit 1985bdb

Browse files
committed
python-stdlib/collections-defaultdict: Add items() function.
This commit adds the `items()` functions to `collections.defaultdict`, acting as a simple proxy to the underlying dictionary container. This fixes #350. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
1 parent 8380c7b commit 1985bdb

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

python-stdlib/collections-defaultdict/collections/defaultdict.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@ def __missing__(self, key):
3333
if self.default_factory is None:
3434
raise KeyError(key)
3535
return self.default_factory()
36+
37+
def items(self):
38+
return self.d.items()

python-stdlib/collections-defaultdict/manifest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
metadata(version="0.3.0")
1+
metadata(version="0.4.0")
22

33
# Originally written by Paul Sokolovsky.
44

python-stdlib/collections-defaultdict/test_defaultdict.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,11 @@
88
assert d[1] == 42
99

1010
assert "foo" not in d
11+
12+
d = defaultdict.defaultdict(list)
13+
for k, v in [('a', 1), ('b', 2), ('c', 3), ('a', 4), ('b', 5), ('c', 6)]:
14+
d[k].append(v)
15+
i = list(sorted(d.items()))
16+
assert i[0] == ('a', [1, 4])
17+
assert i[1] == ('b', [2, 5])
18+
assert i[2] == ('c', [3, 6])

0 commit comments

Comments
 (0)