{"id":4477,"date":"2023-11-29T15:41:58","date_gmt":"2023-11-29T15:41:58","guid":{"rendered":"https:\/\/ibex.tech\/python\/?p=4477"},"modified":"2023-12-15T13:20:50","modified_gmt":"2023-12-15T13:20:50","slug":"dictionary-general","status":"publish","type":"post","link":"https:\/\/ibex.tech\/python\/memory-python\/dictionaries\/dictionary-general","title":{"rendered":".Dictionary general"},"content":{"rendered":"\n<p>Dictionaries in python are similar to \u201cassociative arrays\u201d in some other languages. Dictionaries are indexed by keys, which can be any immutable type, e.g strings and numbers.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Creating a dictionary<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>#Create a doctionary\nmy_dictionary = {}\nmy_dictionary&#91;\"MyKeyA\"] = \"Something\"\nmy_dictionary&#91;\"MyKeyB\"] = \"Something else\"\n\n#Alternative method\n\nmy_dictionary = {\"MyKeyA\": \"Something\", \"MyKeyB\": \"Something else\"}\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Accessing a dictionary<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>print(my_dictionary&#91;\"MyKeyB\"])<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Does dictionary key exist?<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>    if 'MyKeyName' in my_dictionary:\n        print(\"MyKeyName: \" + my_dictionary&#91;'MyKeyName'])<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Dictionaries in python are similar to \u201cassociative arrays\u201d in some other languages. Dictionaries are indexed by keys, which can be any immutable type, e.g strings and numbers. Creating a dictionary Accessing a dictionary Does dictionary key exist?<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[358],"tags":[],"class_list":["post-4477","post","type-post","status-publish","format-standard","hentry","category-dictionaries"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4477","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/comments?post=4477"}],"version-history":[{"count":3,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4477\/revisions"}],"predecessor-version":[{"id":4542,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4477\/revisions\/4542"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/media?parent=4477"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/categories?post=4477"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/tags?post=4477"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}