Michal Kobus | 14e835b | 2019-04-11 14:25:27 +0200 | [diff] [blame] | 1 | from collections import OrderedDict |
| 2 | |
| 3 | |
| 4 | def merge_dicts_ordered(*dict_args, **extra_entries): |
| 5 | """ |
| 6 | Given an arbitrary number of dictionaries, merge them into a |
| 7 | single new dictionary. Later dictionaries take precedence if |
| 8 | a key is shared by multiple dictionaries. |
| 9 | |
| 10 | Extra entries can also be provided via kwargs. These entries |
| 11 | have the highest precedence. |
| 12 | """ |
| 13 | res = OrderedDict() |
| 14 | |
| 15 | for d in dict_args + (extra_entries,): |
| 16 | res.update(d) |
| 17 | |
| 18 | return res |