{"id":47284,"date":"2020-06-02T01:30:34","date_gmt":"2020-06-02T05:30:34","guid":{"rendered":"https:\/\/ibkrcampus.com\/?p=47284"},"modified":"2022-11-21T09:45:37","modified_gmt":"2022-11-21T14:45:37","slug":"all-about-python-dictionaries","status":"publish","type":"post","link":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/all-about-python-dictionaries\/","title":{"rendered":"All About Python Dictionaries"},"content":{"rendered":"\n<p><strong>What are Python dictionaries?<\/strong><\/p>\n\n\n\n<p>A&nbsp;<strong>dictionary<\/strong>&nbsp;is one of Python\u2019s primary data structures. In essence, a&nbsp;<strong>dictionary<\/strong>&nbsp;(also shortened as&nbsp;<strong>dict<\/strong>) is a collection of key-value pairs, similar to an actual dictionary (like the one pictured above). When you look up a word in a dictionary, you find a corresponding definition. Similarly, in a Python&nbsp;<strong>dictionary<\/strong>, each&nbsp;<em>key<\/em>&nbsp;has a corresponding&nbsp;<em>value<\/em>.<\/p>\n\n\n\n<p>In&nbsp;<strong>dictionaries<\/strong>, one key can have only one value. However, the value can be anything from a single number or character, to lists, tuples, other dictionaries, or even functions!<\/p>\n\n\n\n<p><strong>Creating a Dictionary<\/strong><\/p>\n\n\n\n<p>Dictionaries can be created several ways. The most straightforward way is below using curly braces.<\/p>\n\n\n\n<p style=\"background-color:#fcfcdb;font-size:11px\" class=\"has-background\">\n# method 1)<br>\nmapper = {&#8220;a&#8221;: 1, &#8220;b&#8221;: 2, &#8220;c&#8221;:3}\n\n<\/p>\n\n\n\n<p>In this example, we create a dictionary with three elements \u2013 that is, three key-value pairs. The keys are \u201ca\u201d, \u201cb\u201d, and \u201cc\u201d, while the corresponding values are 1, 2, and 3.<\/p>\n\n\n\n<p><strong>Getting the keys and values of a dictionary<\/strong><\/p>\n\n\n\n<p>We can get the keys of our dictionary using the&nbsp;<em>keys<\/em>&nbsp;method.<\/p>\n\n\n\n<p style=\"background-color:#fcfcdb;font-size:11px\" class=\"has-background\">\nmapper.keys()\n\n<\/p>\n\n\n\n<p>Similarly, we can get the values of a dictionary using the&nbsp;<em>values<\/em>&nbsp;method.<\/p>\n\n\n\n<p style=\"background-color:#fcfcdb;font-size:11px\" class=\"has-background\">\nmapper.values()\n<\/p>\n\n\n\n<p><strong>Adding new key-value pairs<\/strong><\/p>\n\n\n\n<p>We can add new key-value pairs to a dictionary using bracket notation.<\/p>\n\n\n\n<p style=\"background-color:#fcfcdb;font-size:11px\" class=\"has-background\">\nmapper[&#8220;d&#8221;] = 4<br><br>\n \nmapper[&#8220;e&#8221;] = 5\n<\/p>\n\n\n\n<p>Likewise, if we want to refine a key-value pair, we also use bracket notation.<\/p>\n\n\n\n<p style=\"background-color:#fcfcdb;font-size:11px\" class=\"has-background\">\nmapper[&#8220;a&#8221;] = 10\n<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"540\" height=\"74\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2020\/06\/python-dictionary-1.png\" alt=\"\" class=\"wp-image-47323 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/06\/python-dictionary-1.png 540w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/06\/python-dictionary-1-300x41.png 300w\" data-sizes=\"(max-width: 540px) 100vw, 540px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 540px; aspect-ratio: 540\/74;\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Removing key-value pairs<\/strong><\/p>\n\n\n\n<p>Key-value pairs can be removed in a couple of different ways. The first is using the&nbsp;<em>pop<\/em>&nbsp;method.<\/p>\n\n\n\n<p style=\"background-color:#fcfcdb;font-size:11px\" class=\"has-background\">\nmapper.pop(&#8220;e&#8221;)\n<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"511\" height=\"145\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2020\/06\/python-dictionary-2.png\" alt=\"\" class=\"wp-image-47324 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/06\/python-dictionary-2.png 511w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/06\/python-dictionary-2-300x85.png 300w\" data-sizes=\"(max-width: 511px) 100vw, 511px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 511px; aspect-ratio: 511\/145;\" \/><\/figure>\n\n\n\n<p>Using the&nbsp;<em>pop<\/em>&nbsp;method both removes the key-value pair and returns the value corresponding to the key input into the method. Alternatively, we can remove a key-value pair using Python\u2019s&nbsp;<em>del<\/em>&nbsp;method. This way does&nbsp;<em>not<\/em>&nbsp;return any value.<\/p>\n\n\n\n<p style=\"background-color:#fcfcdb;font-size:11px\" class=\"has-background\">\ndel mapper[&#8220;d&#8221;]\n<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"458\" height=\"122\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2020\/06\/python-dictionary-3.png\" alt=\"\" class=\"wp-image-47325 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/06\/python-dictionary-3.png 458w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/06\/python-dictionary-3-300x80.png 300w\" data-sizes=\"(max-width: 458px) 100vw, 458px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 458px; aspect-ratio: 458\/122;\" \/><\/figure>\n\n\n\n<p><strong>How to combine two Python dictionaries<\/strong><\/p>\n\n\n\n<p>Dictionaries can be combined using the&nbsp;<em>update<\/em>&nbsp;method. For example, we currently have:<\/p>\n\n\n\n<p><strong>mapper = {\u201ca\u201d, \u201cb\u201d, \u201cc\u201d}<\/strong><\/p>\n\n\n\n<p>Now let\u2019s create another dictionary called extra:<\/p>\n\n\n\n<p style=\"background-color:#fcfcdb;font-size:11px\" class=\"has-background\">\nextra = {&#8220;this&#8221;: &#8220;is&#8221;, &#8220;another&#8221;:&#8221;dictionary&#8221;}\n<\/p>\n\n\n\n<p>Next, let\u2019s combine&nbsp;<em>mapper<\/em>&nbsp;and&nbsp;<em>extra<\/em>.<\/p>\n\n\n\n<p style=\"background-color:#fcfcdb;font-size:11px\" class=\"has-background\">\nmapper.update(extra)\n<\/p>\n\n\n\n<p>Running the&nbsp;<em>update<\/em>&nbsp;method here will update&nbsp;<em>mapper<\/em>&nbsp;to also have the key-value pairs in&nbsp;<em>extra<\/em>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"640\" height=\"196\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2020\/06\/python-dictionary-4.png\" alt=\"\" class=\"wp-image-47347 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/06\/python-dictionary-4.png 640w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/06\/python-dictionary-4-300x92.png 300w\" data-sizes=\"(max-width: 640px) 100vw, 640px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 640px; aspect-ratio: 640\/196;\" \/><\/figure>\n\n\n\n<p><strong>The items method<\/strong><\/p>\n\n\n\n<p>We can convert a dictionary into a list of tuples using the&nbsp;<em>items<\/em>&nbsp;method. Here, each tuple will be a key-value pair. The first line below will create a&nbsp;<em>dict_items<\/em>&nbsp;object, which is iterable, so we can loop over the key-value pairs in this object. However, this object is not indexable \u2013 i.e. trying to run mapper.items()[0] will result in an error. However, if we wanted to reference key-value pairs by index, we can convert this to a list. In practice, we usually would not need to do this conversion.<\/p>\n\n\n\n<p style=\"background-color:#fcfcdb;font-size:11px\" class=\"has-background\">\n# get key-value tuples in dictionary<br>\nmapper.items()<br><br>\n \n# convert to list<br>\nlist(mapper.items())\n<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"640\" height=\"150\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2020\/06\/python-dictionary-5.png\" alt=\"\" class=\"wp-image-47348 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/06\/python-dictionary-5.png 640w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/06\/python-dictionary-5-300x70.png 300w\" data-sizes=\"(max-width: 640px) 100vw, 640px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 640px; aspect-ratio: 640\/150;\" \/><\/figure>\n\n\n\n<p>The&nbsp;<em>items<\/em>&nbsp;method is especially useful when iterating over a dictionary, or when creating a dictionary comprehension, which we\u2019ll discuss next.<\/p>\n\n\n\n<p>Suppose we have dictionary of filenames \u2013 each key is a filename, and each value is a new name that we want to give for the key. Here, we can loop over the items (key-value pairs) in the dictionary and change each file name.<\/p>\n\n\n\n<p style=\"background-color:#fcfcdb;font-size:11px\" class=\"has-background\">\nimport os<br><br>\n \nfiles = {&#8220;file1.txt&#8221;: &#8220;new_file.txt&#8221;, &#8220;file2.txt&#8221;, &#8220;new_file2.txt&#8221;, &#8220;file3.txt&#8221;, &#8220;new_file3.txt&#8221;}<br><br>\n \nfor key,val in files.items():<br>\n    os.rename(key, val)\n<\/p>\n\n\n\n<p>Visit TheAutomatic.net to download ready-to-use code, and read the rest of the article: <a href=\"https:\/\/theautomatic.net\/2020\/04\/15\/all-about-python-dictionaries\/\">https:\/\/theautomatic.net\/2020\/04\/15\/all-about-python-dictionaries\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Andrew Treadway demonstrates how to create a dictionary in Python, add new key-value pairs, and combine dictionaries using the update method.<\/p>\n","protected":false},"author":388,"featured_media":47341,"comment_status":"closed","ping_status":"open","sticky":true,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[343,349,338,341,352,344],"tags":[806,595,7712,7713,7714],"contributors-categories":[13695],"class_list":{"0":"post-47284","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-programing-languages","8":"category-python-development","9":"category-ibkr-quant-news","10":"category-quant-development","11":"category-quant-north-america","12":"category-quant-regions","13":"tag-data-science","14":"tag-python","15":"tag-python-dictionary","16":"tag-python-pop-method","17":"tag-python-tuples","18":"contributors-categories-theautomatic-net"},"pp_statuses_selecting_workflow":false,"pp_workflow_action":"current","pp_status_selection":"publish","acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.9 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>All About Python Dictionaries | IBKR Quant<\/title>\n<meta name=\"description\" content=\"Andrew Treadway demonstrates how to create a dictionary in Python, add new key-value pairs, and combine dictionaries using the update method.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/posts\/47284\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"All About Python Dictionaries | IBKR Quant Blog\" \/>\n<meta property=\"og:description\" content=\"Andrew Treadway demonstrates how to create a dictionary in Python, add new key-value pairs, and combine dictionaries using the update method.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/all-about-python-dictionaries\/\" \/>\n<meta property=\"og:site_name\" content=\"IBKR Campus US\" \/>\n<meta property=\"article:published_time\" content=\"2020-06-02T05:30:34+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-21T14:45:37+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/06\/books-stack.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"900\" \/>\n\t<meta property=\"og:image:height\" content=\"550\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Andrew Treadway\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Andrew Treadway\" \/>\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\">{\n\t    \"@context\": \"https:\\\/\\\/schema.org\",\n\t    \"@graph\": [\n\t        {\n\t            \"@type\": \"NewsArticle\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/all-about-python-dictionaries\\\/#article\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/all-about-python-dictionaries\\\/\"\n\t            },\n\t            \"author\": {\n\t                \"name\": \"Andrew Treadway\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/d4018570a16fb867f1c08412fc9c64bc\"\n\t            },\n\t            \"headline\": \"All About Python Dictionaries\",\n\t            \"datePublished\": \"2020-06-02T05:30:34+00:00\",\n\t            \"dateModified\": \"2022-11-21T14:45:37+00:00\",\n\t            \"mainEntityOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/all-about-python-dictionaries\\\/\"\n\t            },\n\t            \"wordCount\": 606,\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/all-about-python-dictionaries\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2020\\\/06\\\/books-stack.jpg\",\n\t            \"keywords\": [\n\t                \"Data Science\",\n\t                \"Python\",\n\t                \"Python Dictionary\",\n\t                \"Python pop method\",\n\t                \"Python tuples\"\n\t            ],\n\t            \"articleSection\": [\n\t                \"Programming Languages\",\n\t                \"Python Development\",\n\t                \"Quant\",\n\t                \"Quant Development\",\n\t                \"Quant North America\",\n\t                \"Quant Regions\"\n\t            ],\n\t            \"inLanguage\": \"en-US\"\n\t        },\n\t        {\n\t            \"@type\": \"WebPage\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/all-about-python-dictionaries\\\/\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/all-about-python-dictionaries\\\/\",\n\t            \"name\": \"All About Python Dictionaries | IBKR Quant Blog\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\"\n\t            },\n\t            \"primaryImageOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/all-about-python-dictionaries\\\/#primaryimage\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/all-about-python-dictionaries\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2020\\\/06\\\/books-stack.jpg\",\n\t            \"datePublished\": \"2020-06-02T05:30:34+00:00\",\n\t            \"dateModified\": \"2022-11-21T14:45:37+00:00\",\n\t            \"description\": \"Andrew Treadway demonstrates how to create a dictionary in Python, add new key-value pairs, and combine dictionaries using the update method.\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"ReadAction\",\n\t                    \"target\": [\n\t                        \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/all-about-python-dictionaries\\\/\"\n\t                    ]\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"ImageObject\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/all-about-python-dictionaries\\\/#primaryimage\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2020\\\/06\\\/books-stack.jpg\",\n\t            \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2020\\\/06\\\/books-stack.jpg\",\n\t            \"width\": 900,\n\t            \"height\": 550,\n\t            \"caption\": \"Dictionary\"\n\t        },\n\t        {\n\t            \"@type\": \"WebSite\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"name\": \"IBKR Campus US\",\n\t            \"description\": \"Financial Education from Interactive Brokers\",\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"SearchAction\",\n\t                    \"target\": {\n\t                        \"@type\": \"EntryPoint\",\n\t                        \"urlTemplate\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/?s={search_term_string}\"\n\t                    },\n\t                    \"query-input\": {\n\t                        \"@type\": \"PropertyValueSpecification\",\n\t                        \"valueRequired\": true,\n\t                        \"valueName\": \"search_term_string\"\n\t                    }\n\t                }\n\t            ],\n\t            \"inLanguage\": \"en-US\"\n\t        },\n\t        {\n\t            \"@type\": \"Organization\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\",\n\t            \"name\": \"Interactive Brokers\",\n\t            \"alternateName\": \"IBKR\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"logo\": {\n\t                \"@type\": \"ImageObject\",\n\t                \"inLanguage\": \"en-US\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\",\n\t                \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"width\": 669,\n\t                \"height\": 669,\n\t                \"caption\": \"Interactive Brokers\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\"\n\t            },\n\t            \"publishingPrinciples\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/about-ibkr-campus\\\/\",\n\t            \"ethicsPolicy\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/cyber-security-notice\\\/\"\n\t        },\n\t        {\n\t            \"@type\": \"Person\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/d4018570a16fb867f1c08412fc9c64bc\",\n\t            \"name\": \"Andrew Treadway\",\n\t            \"description\": \"Andrew Treadway currently works as a Senior Data Scientist, and has experience doing analytics, software automation, and ETL. He completed a master\u2019s degree in computer science \\\/ machine learning, and an undergraduate degree in pure mathematics. Connect with him on LinkedIn: https:\\\/\\\/www.linkedin.com\\\/in\\\/andrew-treadway-a3b19b103\\\/In addition to TheAutomatic.net blog, he also teaches in-person courses on Python and R through my NYC meetup: more details.\",\n\t            \"sameAs\": [\n\t                \"https:\\\/\\\/theautomatic.net\\\/about-me\\\/\"\n\t            ],\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/author\\\/andrewtreadway\\\/\"\n\t        }\n\t    ]\n\t}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"All About Python Dictionaries | IBKR Quant","description":"Andrew Treadway demonstrates how to create a dictionary in Python, add new key-value pairs, and combine dictionaries using the update method.","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":"https:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/posts\/47284\/","og_locale":"en_US","og_type":"article","og_title":"All About Python Dictionaries | IBKR Quant Blog","og_description":"Andrew Treadway demonstrates how to create a dictionary in Python, add new key-value pairs, and combine dictionaries using the update method.","og_url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/all-about-python-dictionaries\/","og_site_name":"IBKR Campus US","article_published_time":"2020-06-02T05:30:34+00:00","article_modified_time":"2022-11-21T14:45:37+00:00","og_image":[{"width":900,"height":550,"url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/06\/books-stack.jpg","type":"image\/jpeg"}],"author":"Andrew Treadway","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Andrew Treadway","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"NewsArticle","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/all-about-python-dictionaries\/#article","isPartOf":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/all-about-python-dictionaries\/"},"author":{"name":"Andrew Treadway","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/d4018570a16fb867f1c08412fc9c64bc"},"headline":"All About Python Dictionaries","datePublished":"2020-06-02T05:30:34+00:00","dateModified":"2022-11-21T14:45:37+00:00","mainEntityOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/all-about-python-dictionaries\/"},"wordCount":606,"publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/all-about-python-dictionaries\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/06\/books-stack.jpg","keywords":["Data Science","Python","Python Dictionary","Python pop method","Python tuples"],"articleSection":["Programming Languages","Python Development","Quant","Quant Development","Quant North America","Quant Regions"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/all-about-python-dictionaries\/","url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/all-about-python-dictionaries\/","name":"All About Python Dictionaries | IBKR Quant Blog","isPartOf":{"@id":"https:\/\/ibkrcampus.com\/campus\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/all-about-python-dictionaries\/#primaryimage"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/all-about-python-dictionaries\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/06\/books-stack.jpg","datePublished":"2020-06-02T05:30:34+00:00","dateModified":"2022-11-21T14:45:37+00:00","description":"Andrew Treadway demonstrates how to create a dictionary in Python, add new key-value pairs, and combine dictionaries using the update method.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/all-about-python-dictionaries\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/all-about-python-dictionaries\/#primaryimage","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/06\/books-stack.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/06\/books-stack.jpg","width":900,"height":550,"caption":"Dictionary"},{"@type":"WebSite","@id":"https:\/\/ibkrcampus.com\/campus\/#website","url":"https:\/\/ibkrcampus.com\/campus\/","name":"IBKR Campus US","description":"Financial Education from Interactive Brokers","publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ibkrcampus.com\/campus\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/ibkrcampus.com\/campus\/#organization","name":"Interactive Brokers","alternateName":"IBKR","url":"https:\/\/ibkrcampus.com\/campus\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","width":669,"height":669,"caption":"Interactive Brokers"},"image":{"@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/"},"publishingPrinciples":"https:\/\/www.interactivebrokers.com\/campus\/about-ibkr-campus\/","ethicsPolicy":"https:\/\/www.interactivebrokers.com\/campus\/cyber-security-notice\/"},{"@type":"Person","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/d4018570a16fb867f1c08412fc9c64bc","name":"Andrew Treadway","description":"Andrew Treadway currently works as a Senior Data Scientist, and has experience doing analytics, software automation, and ETL. He completed a master\u2019s degree in computer science \/ machine learning, and an undergraduate degree in pure mathematics. Connect with him on LinkedIn: https:\/\/www.linkedin.com\/in\/andrew-treadway-a3b19b103\/In addition to TheAutomatic.net blog, he also teaches in-person courses on Python and R through my NYC meetup: more details.","sameAs":["https:\/\/theautomatic.net\/about-me\/"],"url":"https:\/\/www.interactivebrokers.com\/campus\/author\/andrewtreadway\/"}]}},"jetpack_featured_media_url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/06\/books-stack.jpg","_links":{"self":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/47284","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/users\/388"}],"replies":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/comments?post=47284"}],"version-history":[{"count":0,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/47284\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media\/47341"}],"wp:attachment":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media?parent=47284"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/categories?post=47284"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/tags?post=47284"},{"taxonomy":"contributors-categories","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/contributors-categories?post=47284"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}