Skip to content

Commit 49b4bc1

Browse files
committed
-
1 parent decb521 commit 49b4bc1

File tree

3 files changed

+39
-17
lines changed

3 files changed

+39
-17
lines changed

misc/IDE files/Wing/python_toolbox.wpr

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,7 @@ proj.directory-list = [{'dirloc': loc('../../..'),
2424
'watch_for_changes': True}]
2525
proj.file-type = 'shared'
2626
proj.home-dir = loc('../../..')
27-
proj.launch-config = {loc('../../../python_toolbox/__init__.py'): ('project',
28-
(u'',
29-
'launch-OHU716PSo2P5T54y')),
30-
loc('../../../python_toolbox/binary_search/binary_search_profile.py'): (''\
31-
'project',
32-
(u'',
33-
'launch-OHU716PSo2P5T54y')),
34-
loc('../../../python_toolbox/cute_iter_tools.py'): ('p'\
35-
'roject',
36-
(u'',
37-
'launch-OHU716PSo2P5T54y')),
38-
loc('../../../test_python_toolbox/test_binary_search/test.py'): (''\
39-
'project',
40-
(u'',
41-
'launch-OHU716PSo2P5T54y')),
42-
loc('../../../run_tests.py'): ('custom',
27+
proj.launch-config = {loc('../../../run_tests.py'): ('custom',
4328
('',
4429
'launch-OHU716PSo2P5T54y'))}
4530
testing.auto-test-file-specs = [('glob',

python_toolbox/dict_tools.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,16 @@ def devour_keys(d):
129129
while d:
130130
key = d.iterkeys().next()
131131
del d[key]
132-
yield key
132+
yield key
133+
134+
135+
def sum_dicts(dicts):
136+
'''
137+
Return the sum of a bunch of dicts i.e. all the dicts merged into one.
138+
139+
If there are any collisions, the latest dicts in the sequence win.
140+
'''
141+
result = {}
142+
for dict_ in dicts:
143+
result.update(dict_)
144+
return result
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright 2009-2013 Ram Rachum.
2+
# This program is distributed under the MIT license.
3+
4+
from python_toolbox import dict_tools
5+
6+
7+
def test():
8+
'''Test the basic workings of `sum_dicts`.'''
9+
dict_1 = {1: 2, 3: 4, 5: 6, 1j: 1, 2j: 1, 3j: 1,}
10+
dict_2 = {'a': 'b', 'c': 'd', 'e': 'f', 2j: 2, 3j: 2,}
11+
dict_3 = {'A': 'B', 'C': 'D', 'E': 'F', 3j: 3,}
12+
13+
assert dict_tools.sum_dicts((dict_1, dict_2, dict_3)) == {
14+
1: 2, 3: 4, 5: 6,
15+
'a': 'b', 'c': 'd', 'e': 'f',
16+
'A': 'B', 'C': 'D', 'E': 'F',
17+
1j: 1, 2j: 2, 3j: 3,
18+
}
19+
20+
assert dict_tools.sum_dicts((dict_3, dict_2, dict_1)) == {
21+
1: 2, 3: 4, 5: 6,
22+
'a': 'b', 'c': 'd', 'e': 'f',
23+
'A': 'B', 'C': 'D', 'E': 'F',
24+
1j: 1, 2j: 1, 3j: 1,
25+
}

0 commit comments

Comments
 (0)