{"id":50194,"date":"2020-07-21T16:30:00","date_gmt":"2020-07-21T16:30:00","guid":{"rendered":"https:\/\/icrowdnewswire.com\/?p=2663929"},"modified":"2020-07-21T16:30:00","modified_gmt":"2020-07-21T16:30:00","slug":"how-to-use-dictionaries-in-python","status":"publish","type":"post","link":"http:\/\/ipsnews.net\/business\/2020\/07\/21\/how-to-use-dictionaries-in-python\/","title":{"rendered":"How to use dictionaries in Python"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" width=\"233\" height=\"24\" src=\"https:\/\/icrowdnewswire.com\/wp-content\/uploads\/2020\/06\/4001-logo.png\" class=\"webfeedsFeaturedVisual wp-post-image\" alt=\"\" style=\"display: block; margin-bottom: 5px; clear:both;max-width: 100%;\" link_thumbnail=\"\" \/><\/p>\n<p>Want to seriously level up your coding game? Check out&nbsp;<a href=\"https:\/\/andauth.co\/AnKd7f\" target=\"_blank\" rel=\"noopener noreferrer\" data-vars-outbound-link=\"https:\/\/andauth.co\/AnKd7f\">the Complete 2020 Python Programming Certification Bundle<\/a>, currently&nbsp;<strong>97% off<\/strong>&nbsp;for Android Authority readers.<\/p>\n<div id=\"post-1136937\" class=\"post-content active post-selector \" data-postid=\"1136937\" data-href=\"https:\/\/www.androidauthority.com\/how-to-add-to-a-dictionary-python-1136937\/\">\n<div class=\"post-right content-panel wide content-panel\">\n<div class=\"the-content padded-panel\">\n<div id=\"content-anchor-inner\" class=\"clearfix\">\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/cdn57.androidauthority.net\/wp-content\/uploads\/2020\/07\/Python-Tutorial-1013x675.jpg\" alt=\"How to use dictionaries in Python\" width=\"603\" height=\"402\" \/><\/p>\n<p>One of the first things any new developer should learn when they start Python, is how to create and store variables. These allow you to store and manipulate data, which is key to creating powerful and dynamic programs. One of the most powerful ways to store data in Python is with dictionaries. In this guide, you will learn how to create dictionaries, how to retrieve information, and how to add to a dictionary in Python!<\/p>\n<p><strong>Also read:&nbsp;<\/strong><a href=\"https:\/\/www.androidauthority.com\/how-to-round-in-python-1134475\/\">How to round in Python<\/a><\/p>\n<h2>Basic commands<\/h2>\n<div class=\"post_content_intcont center\">\n<div id=\"custom_html-4\" class=\"widget_text widget clearfix\">\n<div class=\"textwidget custom-html-widget\">&nbsp;<\/div>\n<\/div>\n<\/div>\n<p>First, I&rsquo;ll walk you through the statements you&rsquo;ll need to create and access dictionaries. You&rsquo;ll also learn how to add to a dictionary. Python makes all of this very easy! Then we&rsquo;ll go over what this all means, and why you might want to use a dictionary over another method of storing values.<\/p>\n<p>To create a new dictionary, you simply use curly brackets. You then enter your data, with the key and the value separated by a colon, and each entry separated by a comma:<\/p>\n<div class=\"aa_hljs_description clearfix\"><span class=\"aa_lang_name\">JAVA<\/span><a class=\"aa_clipboard\" data-clipboard-target=\"#hl_41931\" data-vars-outbound-link=\"javascript:void(null)\">SELECT ALL<\/a><\/div>\n<pre id=\"hl_41931\" class=\"hljs java\">newDict={<span class=\"hljs-string\">\"Jeff\"<\/span> : <span class=\"hljs-number\">7701489772<\/span>,<span class=\"hljs-string\">\"Bill\"<\/span> : <span class=\"hljs-number\">7378999911<\/span>, <span class=\"hljs-string\">\"Nancy\"<\/span> : <span class=\"hljs-number\">7711289354<\/span>}<\/pre>\n<p>Note that Python will allow you to mix data types within your dictionary. Here, I have mixed strings and integers. This list stores a set of numbers with the person&rsquo;s first name used as the key. This could be a handy way to quickly grab phone numbers of friends.<\/p>\n<p>We can then retrieve the value based on the key:<\/p>\n<div class=\"aa_hljs_description clearfix\"><span class=\"aa_lang_name\">PHP<\/span><a class=\"aa_clipboard\" data-clipboard-target=\"#hl_20381\" data-vars-outbound-link=\"javascript:void(null)\">SELECT ALL<\/a><\/div>\n<pre id=\"hl_20381\" class=\"hljs php\"><span class=\"hljs-keyword\">print<\/span>(newDict[<span class=\"hljs-string\">\"Jeff\"<\/span>])<\/pre>\n<p>This will print Jeff&rsquo;s number to the screen.<\/p>\n<p>Updating entries is likewise very straightforward:<\/p>\n<div class=\"aa_hljs_description clearfix\"><span class=\"aa_lang_name\">JAVA<\/span><a class=\"aa_clipboard\" data-clipboard-target=\"#hl_85661\" data-vars-outbound-link=\"javascript:void(null)\">SELECT ALL<\/a><\/div>\n<pre id=\"hl_85661\" class=\"hljs java\">newDict[<span class=\"hljs-string\">\"Jeff\"<\/span>] = <span class=\"hljs-number\">7789876224<\/span><\/pre>\n<p>And we can add to a dictionary in Python just as easily:<\/p>\n<div class=\"aa_hljs_description clearfix\"><span class=\"aa_lang_name\">JAVA<\/span><a class=\"aa_clipboard\" data-clipboard-target=\"#hl_87891\" data-vars-outbound-link=\"javascript:void(null)\">SELECT ALL<\/a><\/div>\n<pre id=\"hl_87891\" class=\"hljs java\">newDict[<span class=\"hljs-string\">\"Claire\"<\/span>] = <span class=\"hljs-number\">7711176329<\/span><\/pre>\n<p>Finally, we can delete dictionary entries, clear the entire thing, or completely delete the dictionary entry:<\/p>\n<div class=\"aa_hljs_description clearfix\"><span class=\"aa_lang_name\">PYTHON<\/span><a class=\"aa_clipboard\" data-clipboard-target=\"#hl_54861\" data-vars-outbound-link=\"javascript:void(null)\">SELECT ALL<\/a><\/div>\n<pre id=\"hl_54861\" class=\"hljs python\">Del newDict[&ldquo;Claire&rdquo;]\r\n\r\nnewDict.clear()\r\n\r\n<span class=\"hljs-keyword\">del<\/span> newDict<\/pre>\n<h2>When to use dictionaries in Python<\/h2>\n<div class=\"post_content_intcont center\">\n<div id=\"custom_html-5\" class=\"widget_text widget clearfix\">\n<div class=\"textwidget custom-html-widget\">\n<div id=\"mob-box-ad-a\">&nbsp;<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>That is how to add to a dictionary in Python and much more. But what is a dictionary useful for and why would you want to use one?<\/p>\n<p>Essentially, dictionaries work a lot like lists. This means you can store lots of data in a single place for easy retrieval. We&rsquo;ve previously discussed how to use lists in Python here:<\/p>\n<ul>\n<li><a href=\"https:\/\/www.androidauthority.com\/how-to-add-to-a-list-in-python-1134815\/\">How to use lists in Python<\/a><\/li>\n<\/ul>\n<p>The difference between a dictionary and a list however, is that lists are sequential and use numbers for their indexes. If you insert a new element into a list, this will change the position of all the&nbsp;<em>other&nbsp;<\/em>elements. That means that if we wanted to add new numbers to our list over time, we&rsquo;d have to keep track of which one was which somehow. This could get complicated!<\/p>\n<p>The beauty of a dictionary then, is that the data can be stored in any order, and new entries won&rsquo;t disrupt old ones. Moreover, we know that the index will always remain consistent, and we can use any logical system we like for naming each entry. This is perfect for phone books, but also many other applications that just aren&rsquo;t suited to lists.<\/p>\n<p>To really get a handle on how to add to a dictionary in Python, how to store data in other ways, and how to do&nbsp;<strong>much&nbsp;<\/strong>more, you should consider taking an online course. There is a huge amount to learn when it comes to Python; and these are skills that can enhance your career, improve your workflow, and be extremely rewarding to develop. Check out our guide to the&nbsp;<a href=\"https:\/\/www.androidauthority.com\/best-online-python-courses-1115430\/\">best online Python courses<\/a>, and consider something like the comprehensive Ultimate Python Programmer &amp; Data Certification Bundle. That particular course is currently discounted from $1,800, all the way to $39.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p class=\"tags\">\n<div><strong>See Campaign: <\/strong><a href=\"https:\/\/andauth.co\/AnKd7f\" target=\"_blank\">https:\/\/andauth.co\/AnKd7f<\/a><br \/><b>Contact Information:<\/b><br \/>Adam Sinicki<\/p>\n<p><b>Tags:<\/b><br \/><a href=\"\"><\/a>, <a href=\"https:\/\/icrowdnewswire.com\/category\/news-category\/wire\/\" rel=\"category tag\">Wire<\/a>, <a href=\"https:\/\/icrowdnewswire.com\/category\/global-regions\/united-states\/\" rel=\"category tag\">United States<\/a>, <a href=\"https:\/\/icrowdnewswire.com\/category\/language\/english\/\" rel=\"category tag\">English<\/a><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\" alt=\"image\" width=\"400\" height=\"300\" class=\"cwdfimg\" \/><\/div>\n<div>\n<h3>Contact Information:<\/h3>\n<p>Adam Sinicki<\/p>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" width=\"233\" height=\"24\" src=\"https:\/\/icrowdnewswire.com\/wp-content\/uploads\/2020\/06\/4001-logo.png\" alt=\"\">Want to seriously level up your coding game? Check out&nbsp;the Complete 2020 Python Programming Certification Bundle, currently&nbsp;97% off&nbsp;for Android Authority readers. One of the first things any new developer should learn when they start Python, is how to create and store variables. These allow you to store and manipulate data, which is key to creating &hellip; <a href=\"https:\/\/icrowdnewswire.com\/2020\/07\/21\/how-to-use-dictionaries-in-python\/\">Continue reading <span>How to use dictionaries in Python<\/span><\/a> <a href=\"http:\/\/ipsnews.net\/business\/2020\/07\/21\/how-to-use-dictionaries-in-python\/\" class=\"more-link\">Continue Reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":47,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,22,54],"tags":[],"class_list":["post-50194","post","type-post","status-publish","format-standard","hentry","category-english","category-united-states","category-wire"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to use dictionaries in Python - Business<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/ipsnews.net\/business\/2020\/07\/21\/how-to-use-dictionaries-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to use dictionaries in Python - Business\" \/>\n<meta property=\"og:description\" content=\"Want to seriously level up your coding game? Check out&nbsp;the Complete 2020 Python Programming Certification Bundle, currently&nbsp;97% off&nbsp;for Android Authority readers. One of the first things any new developer should learn when they start Python, is how to create and store variables. These allow you to store and manipulate data, which is key to creating &hellip; Continue reading How to use dictionaries in Python Continue Reading &rarr;\" \/>\n<meta property=\"og:url\" content=\"http:\/\/ipsnews.net\/business\/2020\/07\/21\/how-to-use-dictionaries-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Business\" \/>\n<meta property=\"article:published_time\" content=\"2020-07-21T16:30:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/icrowdnewswire.com\/wp-content\/uploads\/2020\/06\/4001-logo.png\" \/>\n<meta name=\"author\" content=\"Bilal\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Bilal\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"http:\/\/ipsnews.net\/business\/2020\/07\/21\/how-to-use-dictionaries-in-python\/\",\"url\":\"http:\/\/ipsnews.net\/business\/2020\/07\/21\/how-to-use-dictionaries-in-python\/\",\"name\":\"How to use dictionaries in Python - Business\",\"isPartOf\":{\"@id\":\"https:\/\/ipsnews.net\/business\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/ipsnews.net\/business\/2020\/07\/21\/how-to-use-dictionaries-in-python\/#primaryimage\"},\"image\":{\"@id\":\"http:\/\/ipsnews.net\/business\/2020\/07\/21\/how-to-use-dictionaries-in-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/icrowdnewswire.com\/wp-content\/uploads\/2020\/06\/4001-logo.png\",\"datePublished\":\"2020-07-21T16:30:00+00:00\",\"author\":{\"@id\":\"https:\/\/ipsnews.net\/business\/#\/schema\/person\/70b05bacee6cf8a877350412fae25e20\"},\"breadcrumb\":{\"@id\":\"http:\/\/ipsnews.net\/business\/2020\/07\/21\/how-to-use-dictionaries-in-python\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/ipsnews.net\/business\/2020\/07\/21\/how-to-use-dictionaries-in-python\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/ipsnews.net\/business\/2020\/07\/21\/how-to-use-dictionaries-in-python\/#primaryimage\",\"url\":\"https:\/\/icrowdnewswire.com\/wp-content\/uploads\/2020\/06\/4001-logo.png\",\"contentUrl\":\"https:\/\/icrowdnewswire.com\/wp-content\/uploads\/2020\/06\/4001-logo.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/ipsnews.net\/business\/2020\/07\/21\/how-to-use-dictionaries-in-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/ipsnews.net\/business\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to use dictionaries in Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/ipsnews.net\/business\/#website\",\"url\":\"https:\/\/ipsnews.net\/business\/\",\"name\":\"Business\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/ipsnews.net\/business\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/ipsnews.net\/business\/#\/schema\/person\/70b05bacee6cf8a877350412fae25e20\",\"name\":\"Bilal\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/ipsnews.net\/business\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/01d05f3f41cc0f9ca88d2011a983bb3f2e83e3e92e3532188bf201df38d2aea8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/01d05f3f41cc0f9ca88d2011a983bb3f2e83e3e92e3532188bf201df38d2aea8?s=96&d=mm&r=g\",\"caption\":\"Bilal\"},\"sameAs\":[\"https:\/\/icrowdnewswire.com\/fc\"],\"url\":\"http:\/\/ipsnews.net\/business\/author\/bilal\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to use dictionaries in Python - Business","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/ipsnews.net\/business\/2020\/07\/21\/how-to-use-dictionaries-in-python\/","og_locale":"en_US","og_type":"article","og_title":"How to use dictionaries in Python - Business","og_description":"Want to seriously level up your coding game? Check out&nbsp;the Complete 2020 Python Programming Certification Bundle, currently&nbsp;97% off&nbsp;for Android Authority readers. One of the first things any new developer should learn when they start Python, is how to create and store variables. These allow you to store and manipulate data, which is key to creating &hellip; Continue reading How to use dictionaries in Python Continue Reading &rarr;","og_url":"http:\/\/ipsnews.net\/business\/2020\/07\/21\/how-to-use-dictionaries-in-python\/","og_site_name":"Business","article_published_time":"2020-07-21T16:30:00+00:00","og_image":[{"url":"https:\/\/icrowdnewswire.com\/wp-content\/uploads\/2020\/06\/4001-logo.png","type":"","width":"","height":""}],"author":"Bilal","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Bilal","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"http:\/\/ipsnews.net\/business\/2020\/07\/21\/how-to-use-dictionaries-in-python\/","url":"http:\/\/ipsnews.net\/business\/2020\/07\/21\/how-to-use-dictionaries-in-python\/","name":"How to use dictionaries in Python - Business","isPartOf":{"@id":"https:\/\/ipsnews.net\/business\/#website"},"primaryImageOfPage":{"@id":"http:\/\/ipsnews.net\/business\/2020\/07\/21\/how-to-use-dictionaries-in-python\/#primaryimage"},"image":{"@id":"http:\/\/ipsnews.net\/business\/2020\/07\/21\/how-to-use-dictionaries-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/icrowdnewswire.com\/wp-content\/uploads\/2020\/06\/4001-logo.png","datePublished":"2020-07-21T16:30:00+00:00","author":{"@id":"https:\/\/ipsnews.net\/business\/#\/schema\/person\/70b05bacee6cf8a877350412fae25e20"},"breadcrumb":{"@id":"http:\/\/ipsnews.net\/business\/2020\/07\/21\/how-to-use-dictionaries-in-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/ipsnews.net\/business\/2020\/07\/21\/how-to-use-dictionaries-in-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/ipsnews.net\/business\/2020\/07\/21\/how-to-use-dictionaries-in-python\/#primaryimage","url":"https:\/\/icrowdnewswire.com\/wp-content\/uploads\/2020\/06\/4001-logo.png","contentUrl":"https:\/\/icrowdnewswire.com\/wp-content\/uploads\/2020\/06\/4001-logo.png"},{"@type":"BreadcrumbList","@id":"http:\/\/ipsnews.net\/business\/2020\/07\/21\/how-to-use-dictionaries-in-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ipsnews.net\/business\/"},{"@type":"ListItem","position":2,"name":"How to use dictionaries in Python"}]},{"@type":"WebSite","@id":"https:\/\/ipsnews.net\/business\/#website","url":"https:\/\/ipsnews.net\/business\/","name":"Business","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ipsnews.net\/business\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/ipsnews.net\/business\/#\/schema\/person\/70b05bacee6cf8a877350412fae25e20","name":"Bilal","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ipsnews.net\/business\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/01d05f3f41cc0f9ca88d2011a983bb3f2e83e3e92e3532188bf201df38d2aea8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/01d05f3f41cc0f9ca88d2011a983bb3f2e83e3e92e3532188bf201df38d2aea8?s=96&d=mm&r=g","caption":"Bilal"},"sameAs":["https:\/\/icrowdnewswire.com\/fc"],"url":"http:\/\/ipsnews.net\/business\/author\/bilal\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"http:\/\/ipsnews.net\/business\/wp-json\/wp\/v2\/posts\/50194","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/ipsnews.net\/business\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ipsnews.net\/business\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ipsnews.net\/business\/wp-json\/wp\/v2\/users\/47"}],"replies":[{"embeddable":true,"href":"http:\/\/ipsnews.net\/business\/wp-json\/wp\/v2\/comments?post=50194"}],"version-history":[{"count":1,"href":"http:\/\/ipsnews.net\/business\/wp-json\/wp\/v2\/posts\/50194\/revisions"}],"predecessor-version":[{"id":50195,"href":"http:\/\/ipsnews.net\/business\/wp-json\/wp\/v2\/posts\/50194\/revisions\/50195"}],"wp:attachment":[{"href":"http:\/\/ipsnews.net\/business\/wp-json\/wp\/v2\/media?parent=50194"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ipsnews.net\/business\/wp-json\/wp\/v2\/categories?post=50194"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ipsnews.net\/business\/wp-json\/wp\/v2\/tags?post=50194"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}