Revision cdf71b12 lib/utils/algo.py
b/lib/utils/algo.py | ||
---|---|---|
46 | 46 |
return [i for i in seq if i not in seen and not seen.add(i)] |
47 | 47 |
|
48 | 48 |
|
49 |
def JoinDisjointDicts(dict_a, dict_b): |
|
50 |
"""Joins dictionaries with no conflicting keys. |
|
51 |
|
|
52 |
Enforces the constraint that the two key sets must be disjoint, and then |
|
53 |
merges the two dictionaries in a new dictionary that is returned to the |
|
54 |
caller. |
|
55 |
|
|
56 |
@type dict_a: dict |
|
57 |
@param dict_a: the first dictionary |
|
58 |
@type dict_b: dict |
|
59 |
@param dict_b: the second dictionary |
|
60 |
@rtype: dict |
|
61 |
@return: a new dictionary containing all the key/value pairs contained in the |
|
62 |
two dictionaries. |
|
63 |
|
|
64 |
""" |
|
65 |
assert not (set(dict_a) & set(dict_b)), ("Duplicate keys found while joining" |
|
66 |
" %s and %s" % (dict_a, dict_b)) |
|
67 |
result = dict_a.copy() |
|
68 |
result.update(dict_b) |
|
69 |
return result |
|
70 |
|
|
71 |
|
|
49 | 72 |
def FindDuplicates(seq): |
50 | 73 |
"""Identifies duplicates in a list. |
51 | 74 |
|
Also available in: Unified diff