{"id":3472,"date":"2022-12-01T18:47:25","date_gmt":"2022-12-01T18:47:25","guid":{"rendered":"https:\/\/gyanipandit.com\/programming\/?p=3472"},"modified":"2022-12-01T18:47:27","modified_gmt":"2022-12-01T18:47:27","slug":"python-dictionary-items","status":"publish","type":"post","link":"https:\/\/gyanipandit.com\/programming\/python-dictionary-items\/","title":{"rendered":"Python Dictionary items() method with Examples"},"content":{"rendered":"\n<p class=\"has-text-align-center\">Python Dictionary items<\/p>\n\n\n\n<p>Now, we are going to have a look at the items method. The items method returns a view object, which contains the key-value pairs of the dictionary, as tuples. Let\u2019s have a look at an example program, which would help us to understand the items method, and also help us to visualize the output.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"648\" height=\"153\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-items-METHOD.jpg\" alt=\"\" class=\"wp-image-3473\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-items-METHOD.jpg 648w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-items-METHOD-300x71.jpg 300w\" sizes=\"auto, (max-width: 648px) 100vw, 648px\" \/><\/figure>\n<\/div>\n\n\n<h2 class=\"has-text-align-center wp-block-heading\">Python Dictionary items() method<\/h2>\n\n\n\n<p>As you can see in the above program, we are having a simple dictionary, and then we are trying to use the items method. With the items method, we get a view object, which contains all the key, value pairs as tuples. We are directly printing the output, so Let\u2019s have a look at the output now.<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background\">dict_items([(&#8216;one&#8217;, 1), (&#8216;two&#8217;, 2), (&#8216;three&#8217;, 3)])<\/p>\n\n\n\n<p>As you can see, the key-value pairs are there as tuples in a list. So, you can use the items method as and when required. Remember that the items method returns an object which contains the key-value pairs from the dictionary.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python Dictionary items Now, we are going to have a look at the items method. The items method returns a view object, which contains the key-value pairs of the dictionary, as tuples. Let\u2019s have a look at an example program, which would help us to understand the items method, and also help us to visualize [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[26,27],"class_list":{"0":"post-3472","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-python-tutorial","7":"tag-python","8":"tag-python-tutorial"},"_links":{"self":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3472","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/comments?post=3472"}],"version-history":[{"count":2,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3472\/revisions"}],"predecessor-version":[{"id":4148,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3472\/revisions\/4148"}],"wp:attachment":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/media?parent=3472"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/categories?post=3472"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/tags?post=3472"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}