<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jann Anthony Briza on Medium]]></title>
        <description><![CDATA[Stories by Jann Anthony Briza on Medium]]></description>
        <link>https://medium.com/@jannanthonybriza?source=rss-b6407090e5ec------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ltwbO8f1ufoH1SEmS-pdkA@2x.jpeg</url>
            <title>Stories by Jann Anthony Briza on Medium</title>
            <link>https://medium.com/@jannanthonybriza?source=rss-b6407090e5ec------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 07:12:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jannanthonybriza/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Python Dictionary: How To Access Its Value]]></title>
            <link>https://medium.com/@jannanthonybriza/python-dictionary-how-to-access-its-value-7835429adc89?source=rss-b6407090e5ec------2</link>
            <guid isPermaLink="false">https://medium.com/p/7835429adc89</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[python-web-developer]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[python3]]></category>
            <category><![CDATA[python-dictionaries]]></category>
            <dc:creator><![CDATA[Jann Anthony Briza]]></dc:creator>
            <pubDate>Tue, 30 Jun 2020 14:18:38 GMT</pubDate>
            <atom:updated>2020-06-30T14:23:52.273Z</atom:updated>
            <content:encoded><![CDATA[<h4>Let&#39;s talk about ways on getting the value in Python dictionary and when to use it.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wxfEOOTTHL9_Hsclv01oCw@2x.jpeg" /><figcaption><em>Photo from pexels.com</em></figcaption></figure><p>There are two ways of getting the value in Python — dictionary dictionary.get(&quot;attrubute&quot;)and dictionary[&quot;attrbute&quot;]but some engineers are still confused when to use these. First things first, let us know what are the differences between the two.</p><h4>dictionary.get(“attribute”)</h4><p>The get method expects two arguments which are the attribute name and the default value. When the attribute does not exist in the dictionary, the second argument will be the default value otherwise the value will be None.</p><pre>&gt;&gt;&gt; dictionary = {&quot;foo&quot;: &quot;bar&quot;}<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; # Attribute exist in the dictionary.<br>&gt;&gt;&gt; value = dictionary.get(&quot;foo&quot;)<br>&gt;&gt;&gt; print(value)<br>&#39;bar&#39;<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; # Attribute does not exist in the dictionary.<br>&gt;&gt;&gt; value = dictionary.get(&quot;not-existing-attribute&quot;)<br>&gt;&gt;&gt; print(value)<br>None<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; # Attribute does not exist and default value is given.<br>&gt;&gt;&gt; value = dictionary.get(&quot;not-existing-attribute&quot;, &quot;baz&quot;)<br>&gt;&gt;&gt; print(value)<br>&#39;baz&#39;</pre><h4>dictionary[“attribute”]</h4><p>This will find the attribute and get the value in the dictionary, and if the attribute does not exist it will raise a KeyError Exception.</p><pre>&gt;&gt;&gt; dictionary = {&quot;foo&quot;: &quot;bar&quot;}<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; # Attribute exist in the dictionary.<br>&gt;&gt;&gt; value = dictionary[&quot;foo&quot;]<br>&gt;&gt;&gt; print(value)<br>&#39;bar&#39;<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; # Attribute does not exist in the dictionary.<br>&gt;&gt;&gt; value = dictionary[&quot;not-existing-attribute&quot;]<br>Traceback (most recent call last):<br>  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;<br>KeyError: &#39;not-existing-attribute&#39;<br></pre><p>As you notice dictionary.get(&quot;attrubute&quot;) never raises an error. Some developer thinks as a perk, but this is actually risky than raising a KeyError Exception. A data bug will be introduced which is harder to fix when this is not used properly.</p><p>In what scenarios do you think you should use dictionary.get(&quot;attrubute&quot;)?</p><ol><li><strong>User inputs</strong> — are unpredictable so there are times you need to use the get method, but not all the time. There are data that are always present or defined in the dictionary. Metadata and optional parameters are the best time you should use the get method.</li><li><strong>Configurations</strong> — sometimes we get this value in a dictionary. It’s better to use getmethod in this situation because configurations are different in every environment especially in staging or production.</li><li><strong>Deployments</strong> — when you are working on microservices, deployment is risky when it comes to a dictionary. There are times that your application is expecting a new value in a dictionary or not which causes KeyErrorraise condition. To prevent this, use get method temporarily and if the whole feature is totally deployed, change it to explicit way.</li></ol><p>If you don’t find things working in the scenarios above, keep using the explicit way. It keeps the structure simple and always remember the <a href="https://en.wikipedia.org/wiki/KISS_principle">KISS</a> principle.</p><h4>Conclusion</h4><blockquote>Keep using the explicit way, let the <strong>KeyError</strong> raise and fix it. It prevents unexpected data bug and keeps the structure simple.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7835429adc89" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>