{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import mdf_toolbox" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Miscellaneous Utilities" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## `dict_merge`\n", "`dict_merge()` will recursively merge two dictionaries. It takes two dictionaries as arguments, `base` and `addition` (in that order). The `base` dictionary is augmented with fields from `addition`. No data in `base` is overwritten or removed." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "base_dict = {\n", " \"foo\": 1,\n", " \"bar\": 2\n", "}\n", "add_dict = {\n", " \"baz\": 3,\n", " \"bar\": \"not_added\"\n", "}" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'bar': 2, 'baz': 3, 'foo': 1}" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mdf_toolbox.dict_merge(base_dict, add_dict)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.4" } }, "nbformat": 4, "nbformat_minor": 2 }