<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>chainmap Archives - Creatronix</title>
	<atom:link href="https://creatronix.de/tag/chainmap/feed/" rel="self" type="application/rss+xml" />
	<link>https://creatronix.de/tag/chainmap/</link>
	<description>My adventures in code &#38; business</description>
	<lastBuildDate>Mon, 27 Oct 2025 09:43:09 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Python3: ChainMap</title>
		<link>https://creatronix.de/python3-chainmap/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Fri, 23 Nov 2018 13:33:39 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[chainmap]]></category>
		<category><![CDATA[python 3]]></category>
		<guid isPermaLink="false">http://creatronix.de/?p=2440</guid>

					<description><![CDATA[<p>Since Python 3.3 You can chain dictionaries which contain the same key in a prioritized order: from collections import ChainMap prio_1 = {"param_1": "foo"} prio_2 = {"param_1": "foobar", "param_2": "bar"} combined = ChainMap(prio_1, prio_2) print(combined["param_1"]) # outputs 'foo' print(combined["param_2"]) # outputs 'bar' The param_1 from the prio_1 dictionary is dominant, so it isn&#8217;t overwritten by&#8230;</p>
<p>The post <a href="https://creatronix.de/python3-chainmap/">Python3: ChainMap</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Since Python 3.3 You can chain dictionaries which contain the same key in a prioritized order:</p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-python" data-lang="Python"><code>from collections import ChainMap 

prio_1 = {"param_1": "foo"} 
prio_2 = {"param_1": "foobar", "param_2": "bar"} 

combined = ChainMap(prio_1, prio_2) 

print(combined["param_1"]) # outputs 'foo' 
print(combined["param_2"]) # outputs 'bar'</code></pre>
</div>
<p>The param_1 from the prio_1 dictionary is dominant, so it isn&#8217;t overwritten by the key-value pair from prio_2 dict. prio_2 dict just adds the param_2 because it is not yet in the ChainMap.</p>
<p>The nice thing is that no information is lost, the ChainMap object contains both dictionaries.</p>
<p>You can use it for example in a situation where you want to chain arguments from argparse, os.environ and default parameters. <a href="https://docs.python.org/3/library/collections.html#chainmap-examples-and-recipes">See here</a></p>
<p>&nbsp;</p>
<p>The post <a href="https://creatronix.de/python3-chainmap/">Python3: ChainMap</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
