{"id":18573,"date":"2021-08-26T15:37:15","date_gmt":"2021-08-26T10:07:15","guid":{"rendered":"https:\/\/tutorial.eyehunts.com\/?p=18573"},"modified":"2022-02-04T18:35:11","modified_gmt":"2022-02-04T13:05:11","slug":"get-keys-of-dictionary-python-example-code","status":"publish","type":"post","link":"https:\/\/tutorial.eyehunts.com\/python\/get-keys-of-dictionary-python-example-code\/","title":{"rendered":"Get keys of Dictionary Python | Example code"},"content":{"rendered":"\n<p>Use the key() method to get keys of Dictionary in Python. It doesn&#8217;t take any <a href=\"https:\/\/tutorial.eyehunts.com\/python\/start-stop-step-python-slice-parameters\/\">parameters <\/a>and <a href=\"https:\/\/tutorial.eyehunts.com\/python\/python-return-if-else-one-line-example-code\/\">returns <\/a>a view <a href=\"https:\/\/tutorial.eyehunts.com\/python\/python-check-if-the-object-is-string-example-code\/\">object <\/a>that displays a list of all the keys.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dict.keys()<\/code><\/pre>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"example-get-keys-of-dictionary-in-python\"><strong>Example get keys of Dictionary in Python<\/strong><\/h2>\n\n\n\n<p>Simple example code.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>emp = {'name': 'John', 'age': 30, 'salary': 70000}\n\nprint(emp.keys())\n<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong>: <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"442\" height=\"113\" src=\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Get-keys-of-Dictionary-Python.jpg?resize=442%2C113&#038;ssl=1\" alt=\"Get keys of Dictionary Python\" class=\"wp-image-18605\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"example-get-dictionary-keys-as-a-list-in-python\"><strong>Example get dictionary keys as a list in Python<\/strong><\/h3>\n\n\n\n<p>Python program with a custom function to get dictionary keys as a list.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def get_list(d):\n    return d.keys()\n\n\n# Driver program\ndict1 = {1: 'A', 2: 'B', 3: 'C'}\nprint(get_list(dict1))\n<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong>: dict_keys([1, 2, 3])<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><strong>Another example gets a pure list of keys from a given dictionary<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def get_list(d):\n    lst = &#91;]\n    for key in d.keys():\n        lst.append(key)\n\n    return lst\n\n\n# Driver program\ndict1 = {1: 'A', 2: 'B', 3: 'C'}\nprint(get_list(dict1))\n<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong>: [1, 2, 3]<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Do comment if you have any questions or suggestions on this Python dict tutorial.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>Note:<\/strong> IDE:&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/www.jetbrains.com\/pycharm\/\" target=\"_blank\">PyCharm<\/a>&nbsp;2021.3.3 (Community Edition)<\/p><p>Windows 10<\/p><p><strong>Python 3.10.1<\/strong><\/p><p>All<strong>&nbsp;Python Examples&nbsp;are in&nbsp;Python&nbsp;3<\/strong>, so Maybe its different from python 2 or upgraded versions.<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Use the key() method to get keys of Dictionary in Python. It doesn&#8217;t take any parameters and returns a view object that displays a list of all the keys. Example get keys of Dictionary in Python Simple example code. Output: Example get dictionary keys as a list in Python Python program with a custom function&hellip;&nbsp;<a href=\"https:\/\/tutorial.eyehunts.com\/python\/get-keys-of-dictionary-python-example-code\/\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">Get keys of Dictionary Python | Example code<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[30],"tags":[136,101],"post_series":[],"class_list":["post-18573","post","type-post","status-publish","format-standard","hentry","category-python","tag-python-code","tag-python-dictionary"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.1.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Get keys of Dictionary Python | Example code - EyeHunts<\/title>\n<meta name=\"description\" content=\"Use key() method to get keys of Dictionary in Python. It doesn&#039;t take any parameters and returns a view object that displays a list of all\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/tutorial.eyehunts.com\/python\/get-keys-of-dictionary-python-example-code\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Get keys of Dictionary Python | Example code - EyeHunts\" \/>\n<meta property=\"og:description\" content=\"Use key() method to get keys of Dictionary in Python. It doesn&#039;t take any parameters and returns a view object that displays a list of all\" \/>\n<meta property=\"og:url\" content=\"https:\/\/tutorial.eyehunts.com\/python\/get-keys-of-dictionary-python-example-code\/\" \/>\n<meta property=\"og:site_name\" content=\"Tutorial\" \/>\n<meta property=\"article:published_time\" content=\"2021-08-26T10:07:15+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-02-04T13:05:11+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Get-keys-of-Dictionary-Python.jpg\" \/>\n<meta name=\"author\" content=\"Rohit\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rohit\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/get-keys-of-dictionary-python-example-code\/\",\"url\":\"https:\/\/tutorial.eyehunts.com\/python\/get-keys-of-dictionary-python-example-code\/\",\"name\":\"Get keys of Dictionary Python | Example code - EyeHunts\",\"isPartOf\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/get-keys-of-dictionary-python-example-code\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/get-keys-of-dictionary-python-example-code\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Get-keys-of-Dictionary-Python.jpg\",\"datePublished\":\"2021-08-26T10:07:15+00:00\",\"dateModified\":\"2022-02-04T13:05:11+00:00\",\"author\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1\"},\"description\":\"Use key() method to get keys of Dictionary in Python. It doesn't take any parameters and returns a view object that displays a list of all\",\"breadcrumb\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/get-keys-of-dictionary-python-example-code\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/tutorial.eyehunts.com\/python\/get-keys-of-dictionary-python-example-code\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/get-keys-of-dictionary-python-example-code\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Get-keys-of-Dictionary-Python.jpg?fit=442%2C113&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Get-keys-of-Dictionary-Python.jpg?fit=442%2C113&ssl=1\",\"width\":442,\"height\":113},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/get-keys-of-dictionary-python-example-code\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/tutorial.eyehunts.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Get keys of Dictionary Python | Example code\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#website\",\"url\":\"https:\/\/tutorial.eyehunts.com\/\",\"name\":\"Tutorial\",\"description\":\"By EyeHunts\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/tutorial.eyehunts.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1\",\"name\":\"Rohit\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971\",\"contentUrl\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971\",\"caption\":\"Rohit\"},\"description\":\"Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology &amp; like learning technical.\",\"url\":\"https:\/\/tutorial.eyehunts.com\/author\/rohit\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Get keys of Dictionary Python | Example code - EyeHunts","description":"Use key() method to get keys of Dictionary in Python. It doesn't take any parameters and returns a view object that displays a list of all","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:\/\/tutorial.eyehunts.com\/python\/get-keys-of-dictionary-python-example-code\/","og_locale":"en_US","og_type":"article","og_title":"Get keys of Dictionary Python | Example code - EyeHunts","og_description":"Use key() method to get keys of Dictionary in Python. It doesn't take any parameters and returns a view object that displays a list of all","og_url":"https:\/\/tutorial.eyehunts.com\/python\/get-keys-of-dictionary-python-example-code\/","og_site_name":"Tutorial","article_published_time":"2021-08-26T10:07:15+00:00","article_modified_time":"2022-02-04T13:05:11+00:00","og_image":[{"url":"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Get-keys-of-Dictionary-Python.jpg","type":"","width":"","height":""}],"author":"Rohit","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Rohit","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/tutorial.eyehunts.com\/python\/get-keys-of-dictionary-python-example-code\/","url":"https:\/\/tutorial.eyehunts.com\/python\/get-keys-of-dictionary-python-example-code\/","name":"Get keys of Dictionary Python | Example code - EyeHunts","isPartOf":{"@id":"https:\/\/tutorial.eyehunts.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/get-keys-of-dictionary-python-example-code\/#primaryimage"},"image":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/get-keys-of-dictionary-python-example-code\/#primaryimage"},"thumbnailUrl":"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Get-keys-of-Dictionary-Python.jpg","datePublished":"2021-08-26T10:07:15+00:00","dateModified":"2022-02-04T13:05:11+00:00","author":{"@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1"},"description":"Use key() method to get keys of Dictionary in Python. It doesn't take any parameters and returns a view object that displays a list of all","breadcrumb":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/get-keys-of-dictionary-python-example-code\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/tutorial.eyehunts.com\/python\/get-keys-of-dictionary-python-example-code\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/tutorial.eyehunts.com\/python\/get-keys-of-dictionary-python-example-code\/#primaryimage","url":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Get-keys-of-Dictionary-Python.jpg?fit=442%2C113&ssl=1","contentUrl":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Get-keys-of-Dictionary-Python.jpg?fit=442%2C113&ssl=1","width":442,"height":113},{"@type":"BreadcrumbList","@id":"https:\/\/tutorial.eyehunts.com\/python\/get-keys-of-dictionary-python-example-code\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/tutorial.eyehunts.com\/"},{"@type":"ListItem","position":2,"name":"Get keys of Dictionary Python | Example code"}]},{"@type":"WebSite","@id":"https:\/\/tutorial.eyehunts.com\/#website","url":"https:\/\/tutorial.eyehunts.com\/","name":"Tutorial","description":"By EyeHunts","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/tutorial.eyehunts.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1","name":"Rohit","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/image\/","url":"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971","contentUrl":"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971","caption":"Rohit"},"description":"Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology &amp; like learning technical.","url":"https:\/\/tutorial.eyehunts.com\/author\/rohit\/"}]}},"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":22540,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-get-nested-dictionary-keys-example-code\/","url_meta":{"origin":18573,"position":0},"title":"Python get nested dictionary keys | Example code","author":"Rohit","date":"November 19, 2021","format":false,"excerpt":"Just iterate every inner dictionary one by one and get nested dictionary keys in Python. Example get nested dictionary keys in Python Simple example code using for loop to iterate a given dictionary. In this method, you will get all keys of the inner dictionary. Employee = { 'emp1': {\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Python get nested dictionary keys","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/11\/Python-get-nested-dictionary-keys.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":18853,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-create-empty-dictionary-with-keys-example-code\/","url_meta":{"origin":18573,"position":1},"title":"Python create empty dictionary with keys | Example code","author":"Rohit","date":"August 31, 2021","format":false,"excerpt":"Use dict.fromkeys() to create an empty dictionary with keys to an empty value in Python. dict.fromkeys(keys) Example create an empty dictionary with keys in Python Simple example code. keys = [\"A\", \"B\", \"C\", \"D\"] d = dict.fromkeys(keys) print(d) Output: Another example By iterating through the list keys = [\"A\", \"B\",\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Python create empty dictionary with keys","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Python-create-empty-dictionary-with-keys.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Python-create-empty-dictionary-with-keys.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Python-create-empty-dictionary-with-keys.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":18771,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-create-dictionary-from-list-of-keys-and-values-example-code\/","url_meta":{"origin":18573,"position":2},"title":"Python create dictionary from list of keys and values | Example code","author":"Rohit","date":"August 29, 2021","format":false,"excerpt":"Use the zip() function to create a dictionary from a list of keys and values in Python. This function allows merging two lists together. Python create a dictionary from a list of keys and values Example Simple example code. Use one list as the keys for the dictionary and the\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Python create dictionary from list of keys and values","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Python-create-dictionary-from-list-of-keys-and-values.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":18767,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-convert-list-to-dictionary-keys-example-code\/","url_meta":{"origin":18573,"position":3},"title":"Python convert list to dictionary keys | Example code","author":"Rohit","date":"October 27, 2021","format":false,"excerpt":"Using Dictionary Comprehension or zip() function will convert the list to dictionary keys in Python. If you have 2 lists then one list value will be a key and another one is used as the value. A single list can be used to convert a key for a dictionary but\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Python convert list to dictionary keys","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Python-convert-list-to-dictionary-keys.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Python-convert-list-to-dictionary-keys.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Python-convert-list-to-dictionary-keys.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":18721,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-enumerate-dictionary-example-code\/","url_meta":{"origin":18573,"position":4},"title":"Python enumerate dictionary | Example code","author":"Rohit","date":"November 14, 2021","format":false,"excerpt":"Python allows you to enumerate both keys and values of a dictionary. In the normal case, you enumerate the keys of the dictionary but in this tutorial, you will get examples of how to enumerate through both keys and values. the enumerate() function returns an iterator that yields tuples containing\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Python enumerate dictionary","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/11\/Python-enumerate-dictionary.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":16289,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-add-to-dict-in-a-loop-adding-item-to-dictionary-within-loop-example\/","url_meta":{"origin":18573,"position":5},"title":"Python add to dict in a loop | Adding item to Dictionary within loop example","author":"Rohit","date":"July 10, 2021","format":false,"excerpt":"You can add keys and to dict in a loop in python. Add an item to a dictionary by inserting a new index key into the dictionary, then assigning it a particular value. Python add to the dictionary in a loop example Simple python code: Add key and value into\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Python add to dict in a loop","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/07\/Python-add-to-dict-in-a-loop.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/18573","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/comments?post=18573"}],"version-history":[{"count":1,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/18573\/revisions"}],"predecessor-version":[{"id":24744,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/18573\/revisions\/24744"}],"wp:attachment":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/media?parent=18573"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/categories?post=18573"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/tags?post=18573"},{"taxonomy":"post_series","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/post_series?post=18573"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}