<?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 Shailesh Jiwana on Medium]]></title>
        <description><![CDATA[Stories by Shailesh Jiwana on Medium]]></description>
        <link>https://medium.com/@shaileshjiwana15219?source=rss-42258693f3d0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Shailesh Jiwana on Medium</title>
            <link>https://medium.com/@shaileshjiwana15219?source=rss-42258693f3d0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 23:03:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shaileshjiwana15219/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[Mastering Python Dictionaries: Complete Guide to Built-In Dictionary Methods and Functions]]></title>
            <link>https://medium.com/@shaileshjiwana15219/mastering-python-dictionaries-complete-guide-to-built-in-dictionary-methods-and-functions-8c2ecb724448?source=rss-42258693f3d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c2ecb724448</guid>
            <dc:creator><![CDATA[Shailesh Jiwana]]></dc:creator>
            <pubDate>Tue, 25 Aug 2026 06:56:58 GMT</pubDate>
            <atom:updated>2026-08-25T06:56:58.793Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-1xNo77QRMUx3NrZ.jpg" /></figure><p>Python dictionaries are among the most powerful and flexible built-in data types, allowing developers to store information efficiently using <strong>key-value pairs</strong>. Whether you are building web backends, managing configurations, or parsing JSON data, knowing how to manipulate dictionaries is essential.</p><p>If you are preparing for coding interviews or searching for a quick reference guide on <strong>Python dictionary functions</strong>, <strong>built-in dictionary methods</strong>, and <strong>Python data structures</strong>, this blog post covers every core function explained in a single sentence with practical examples.</p><h3>Complete List of Python Dictionary Methods and Functions</h3><h3>1. clear()</h3><ul><li><strong>Explanation:</strong> The clear() method removes all key-value pairs from the dictionary, leaving it completely empty.</li><li><strong>Example</strong>:</li></ul><p>Python</p><pre>student = {&quot;name&quot;: &quot;Alice&quot;, &quot;age&quot;: 21}<br>student.clear()<br>print(student)  # Output: {}</pre><h3>2. copy()</h3><ul><li><strong>Explanation:</strong> The copy() method returns a shallow copy of the target dictionary.</li><li><strong>Example</strong>:</li></ul><p>Python</p><pre>original = {&quot;a&quot;: 1, &quot;b&quot;: 2}<br>clone = original.copy()<br>print(clone)  # Output: {&#39;a&#39;: 1, &#39;b&#39;: 2}</pre><h3>3. fromkeys()</h3><ul><li><strong>Explanation:</strong> The fromkeys() method creates a new dictionary from a provided sequence of keys, optionally assigning a shared default value to each.</li><li><strong>Example:</strong></li></ul><p>Python</p><pre>keys = [&quot;status&quot;, &quot;active&quot;, &quot;verified&quot;] <br>default_dict = dict.fromkeys(keys, False) <br>print(default_dict)  <br># Output: {&#39;status&#39;: False, &#39;active&#39;: False, &#39;verified&#39;: False}</pre><h3>4. get()</h3><ul><li><strong>Explanation:</strong> The get() method safely retrieves the value of a specified key without throwing a KeyError if the key is missing.</li><li><strong>Example:</strong></li></ul><p>Python</p><pre>user = {&quot;name&quot;: &quot;Bob&quot;} <br>print(user.get(&quot;age&quot;, 18))  # Output: 18 (since &#39;age&#39; doesn&#39;t exist)</pre><h3>5. items()</h3><ul><li><strong>Explanation:</strong> The items() method returns a dynamic view object displaying a list of a dictionary’s key-value tuple pairs.</li><li><strong>Example:</strong></li></ul><p>Python</p><pre>scores = {&quot;math&quot;: 90, &quot;science&quot;: 85} <br>print(list(scores.items()))  # Output: [(&#39;math&#39;, 90), (&#39;science&#39;, 85)]</pre><h3>6. keys()</h3><ul><li><strong>Explanation:</strong> The keys() method returns a view object that contains all the unique keys present in the dictionary.</li><li><strong>Example:</strong></li></ul><p>Python</p><pre>car = {&quot;brand&quot;: &quot;Tesla&quot;, &quot;model&quot;: &quot;Model 3&quot;} <br>print(list(car.keys()))  # Output: [&#39;brand&#39;, &#39;model&#39;]</pre><h3>7. pop()</h3><ul><li><strong>Explanation:</strong> The pop() method removes a specified key from the dictionary and returns its corresponding value.</li><li><strong>Example:</strong></li></ul><p>Python</p><pre>item = {&quot;pen&quot;: 10, &quot;pencil&quot;: 5} <br>cost = item.pop(&quot;pencil&quot;) print(cost)  # Output: 5</pre><h3>8. popitem()</h3><ul><li><strong>Explanation:</strong> The popitem() method removes and returns the last inserted key-value pair as a tuple following Last-In, First-Out (LIFO) order.</li><li><strong>Example:</strong></li></ul><p>Python</p><pre>settings = {&quot;theme&quot;: &quot;dark&quot;, &quot;notifications&quot;: True}<br>print(settings.popitem())  # Output: (&#39;notifications&#39;, True)</pre><h3>9. setdefault()</h3><ul><li><strong>Explanation:</strong> The setdefault() method returns the value of a key if it exists; otherwise, it inserts the key with a specified default value.</li><li><strong>Example:</strong></li></ul><p>Python</p><pre>data = {&quot;x&quot;: 10} val = data.setdefault(&quot;y&quot;, 20) <br>print(data)  # Output: {&#39;x&#39;: 10, &#39;y&#39;: 20}</pre><h3>10. update()</h3><ul><li><strong>Explanation:</strong> The update() method merges key-value pairs from another dictionary or iterable into the current dictionary.</li><li><strong>Example:</strong></li></ul><p>Python</p><pre>profile = {&quot;name&quot;: &quot;Charlie&quot;} <br>profile.update({&quot;age&quot;: 25, &quot;role&quot;: &quot;Admin&quot;}) <br>print(profile)  <br># Output: {&#39;name&#39;: &#39;Charlie&#39;, &#39;age&#39;: 25, &#39;role&#39;: &#39;Admin&#39;}</pre><h3>11. values()</h3><ul><li><strong>Explanation:</strong> The values() method returns a view object containing all the values stored inside the dictionary.</li><li><strong>Example:</strong></li></ul><p>Python</p><pre>grades = {&quot;A&quot;: 90, &quot;B&quot;: 80, &quot;C&quot;: 70}<br>print(list(grades.values()))  # Output: [90, 80, 70]</pre><h3>12. Built-in Functions Acting on Dictionaries (len(), str(), sorted())</h3><ul><li><strong>Explanation:</strong> General built-in Python functions like len() count the items, str() returns a string representation, and sorted() sorts the keys of a dictionary.</li><li><strong>Example:</strong></li></ul><p>Python</p><pre>inventory = {&quot;apples&quot;: 5, &quot;bananas&quot;: 12}<br>print(len(inventory))       # Output: 2 print(sorted(inventory))<br># Output: [&#39;apples&#39;, &#39;bananas&#39;]</pre><h3>Conclusion</h3><p>Mastering these built-in Python dictionary functions and methods will drastically streamline your code efficiency and data management workflows. Bookmark this comprehensive guide for your next Python development project or interview preparation!</p><p>What specific Python data structure or algorithm would you like to explore next?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c2ecb724448" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>