{"id":241,"date":"2016-01-09T10:01:03","date_gmt":"2016-01-09T10:01:03","guid":{"rendered":"http:\/\/mr-west.uk\/python\/?page_id=241"},"modified":"2025-01-12T11:33:33","modified_gmt":"2025-01-12T11:33:33","slug":"dictionaries","status":"publish","type":"page","link":"https:\/\/learnlearn.uk\/python\/dictionaries\/","title":{"rendered":"Dictionaries"},"content":{"rendered":"<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">Introduction<\/h2>\n<div class=\"tabcontent\">\n\n<div class=\"arconix-column-two-thirds\">\n<p><strong>What are dictionaries?<\/strong><\/p>\n<p>Dictionaries are data structures that store<strong> key:value<\/strong> pairs.<\/p>\n<p>The key is the thing that you use to find an item in a dictionary.<\/p>\n<p>The value is the item that is stored under that key.<\/p>\n<p><strong>When should I use them?<\/strong><\/p>\n<p>Dictionaries should be used where you need to store data in a data structure and access it by it&#8217;s name.<\/p>\n<p>Dictionaries are un-ordered, so that order that you put an item in a dictionary is not necessarily the order that your item is stored in. Other other words if you need to maintain data order, use a list instead.<\/p>\n<\/div>\n<div class=\"arconix-column-one-third\">\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-778\" src=\"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2016\/01\/dictionary-300x200.jpg\" alt=\"dictionary\" width=\"300\" height=\"200\" srcset=\"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2016\/01\/dictionary-300x200.jpg 300w, https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2016\/01\/dictionary-768x511.jpg 768w, https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2016\/01\/dictionary-600x399.jpg 600w, https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2016\/01\/dictionary.jpg 960w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<\/div>\n<p>\n<\/div><h2 class=\"tabtitle\">Video Tutorial<\/h2>\n<div class=\"tabcontent\">\n<br \/>\n<iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/videoseries?list=PLfd-8l91Lb4Xm4yYYuMnhvhRewu-4oJ1H\" width=\"853\" height=\"480\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p><a href=\"https:\/\/drive.google.com\/drive\/folders\/1MOMIop7hmmljYgjaJ3SfPJjax_KwyCaw?usp=sharing\">Youtube Blocked? Here are the videos on Google Drive instead<\/a><\/p>\n\n<\/div><h2 class=\"tabtitle\">Counter Example<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Counter Example<\/h3>\n<p>Dictionaries are often used as counters to keep a tally of items. Here is a simple example to show you how it works.<\/p>\n<p><iframe loading=\"lazy\" src=\"https:\/\/trinket.io\/embed\/python\/bd5f9f0d48\" width=\"100%\" height=\"600\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n\n<\/div><h2 class=\"tabtitle\">More Examples<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Script Examples<\/h3>\n<p>Here are a few live script examples to have a play with to see what Dictionaries could be useful for.<\/p>\n<p><a href=\"https:\/\/trinket.io\/embed\/python\/911d5853cf\" target=\"_blank\" rel=\"noopener\">https:\/\/trinket.io\/embed\/python\/911d5853cf<\/a><\/p>\n<p><a href=\"https:\/\/trinket.io\/embed\/python\/d776e4ce2e\" target=\"_blank\" rel=\"noopener\">https:\/\/trinket.io\/embed\/python\/d776e4ce2e<\/a><\/p>\n<p><a href=\"https:\/\/trinket.io\/embed\/python\/0a2d1fb7dc\" target=\"_blank\" rel=\"noopener\">https:\/\/trinket.io\/embed\/python\/0a2d1fb7dc<\/a><\/p>\n<p><a href=\"https:\/\/trinket.io\/embed\/python\/be9e23f742\" target=\"_blank\" rel=\"noopener\">https:\/\/trinket.io\/embed\/python\/be9e23f742<\/a><\/p>\n<p><a href=\"https:\/\/trinket.io\/embed\/python\/d9208fd80e\" target=\"_blank\" rel=\"noopener\">https:\/\/trinket.io\/embed\/python\/d9208fd80e<\/a><\/p>\n\n<\/div><h2 class=\"tabtitle\">Challenge 29<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Challenge 29 &#8211; Takeaway App<\/h3>\n<p>Create a program with a dictionary containing the names and telephone numbers of 5 takeaways.<\/p>\n<p><strong><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-886\" src=\"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2017\/09\/bronze-star25.png\" alt=\"\" width=\"25\" height=\"25\" \/>\u00a0Bronze<\/strong><\/p>\n<ul>\n<li>Your program should ask the user to enter a takeaway name, and then print out the matching number.<\/li>\n<\/ul>\n<p><strong><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-887\" src=\"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2017\/09\/silver-star25.png\" alt=\"\" width=\"25\" height=\"25\" \/>\u00a0Silver<\/strong><\/p>\n<ul>\n<li>If the takeaway cannot be found the print out an appropriate message.<\/li>\n<\/ul>\n<p><strong><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-888\" src=\"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2017\/09\/gold-star-25.png\" alt=\"\" width=\"25\" height=\"25\" \/>\u00a0 Gold<\/strong><\/p>\n<p>At the start of the program it should print out the names of all the takeaways, so the user know which options they have to choose from.<\/p>\n\n<\/div><h2 class=\"tabtitle\">30<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Challenge 30 &#8211; Car counter<\/h3>\n<p>Create a program that a user can use to keep track of what make of cars pass by on a busy road.<\/p>\n<p><strong><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-886\" src=\"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2017\/09\/bronze-star25.png\" alt=\"\" width=\"25\" height=\"25\" \/>\u00a0Bronze<\/strong><\/p>\n<ul>\n<li>The program should ask for 10 cars and should keep track of the number of cars of that make, using a dictionary.<\/li>\n<\/ul>\n<p><strong><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-887\" src=\"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2017\/09\/silver-star25.png\" alt=\"\" width=\"25\" height=\"25\" \/>\u00a0Silver<\/strong><\/p>\n<ul>\n<li>The program should be adapted so that cars will be keep being added until an empty string is entered, then it should print out the contents of the dictionary.<\/li>\n<\/ul>\n<p><strong><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-888\" src=\"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2017\/09\/gold-star-25.png\" alt=\"\" width=\"25\" height=\"25\" \/>\u00a0Gold<\/strong><\/p>\n<ul>\n<li>The program should display the contents of the dictionary, sorted in frequency order (highest frequency first).<\/li>\n<\/ul>\n\n<\/div><h2 class=\"tabtitle\">31<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Challenge 31 &#8211; Telephone Contacts app<\/h3>\n<p>You should create an app that asks the user to enter some contact names and telephone numbers.<\/p>\n<p>Your program should store each name and telephone number in a dictionary<\/p>\n<p><strong><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-886\" src=\"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2017\/09\/bronze-star25.png\" alt=\"\" width=\"25\" height=\"25\" \/>\u00a0Bronze<\/strong><\/p>\n<ul>\n<li>The program should ask the user to enter 3 names \/ numbers.<\/li>\n<li>The program should display all the names and numbers at the end of the program.<\/li>\n<\/ul>\n<p><strong><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-887\" src=\"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2017\/09\/silver-star25.png\" alt=\"\" width=\"25\" height=\"25\" \/>\u00a0Silver<\/strong><\/p>\n<ul>\n<li>The program should keep adding names \/ numbers until the user enters and empty string for a name, then it should stop.<\/li>\n<li>The program should give the user the option to search for a contact&#8217;s telephone number.<\/li>\n<\/ul>\n<p><strong><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-888\" src=\"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2017\/09\/gold-star-25.png\" alt=\"\" width=\"25\" height=\"25\" \/>\u00a0Gold<\/strong><\/p>\n<ul>\n<li>Your program should be adapted to have 4 screens:\n<ul>\n<li>A main menu<\/li>\n<li>An add screen ( to add new contacts<\/li>\n<li>A search screen (to search for contacts)<\/li>\n<li>A view screen(to display all contacts)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n<\/div><h2 class=\"tabtitle\">32<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Challenge 32 &#8211; Game Stats adder.<\/h3>\n<p>You should create a program that allows the user to add stats for a player. (e.g. strength 20, damage 30 , speed 50, etc)<\/p>\n<p><strong><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-886\" src=\"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2017\/09\/bronze-star25.png\" alt=\"\" width=\"25\" height=\"25\" \/>Bronze<\/strong><\/p>\n<ul>\n<li>Your program should add all the stats from one character and then print out a full stat sheet at the end.<\/li>\n<\/ul>\n<p><strong><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-887\" src=\"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2017\/09\/silver-star25.png\" alt=\"\" width=\"25\" height=\"25\" \/>\u00a0Silver<\/strong><\/p>\n<ul>\n<li>Your program should include a list of valid stat categories and ensure that only valid categories are added.<\/li>\n<li>Your program should check the amounts entered are valid integers between the range 0 to 100.<\/li>\n<\/ul>\n<p><strong><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-888\" src=\"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2017\/09\/gold-star-25.png\" alt=\"\" width=\"25\" height=\"25\" \/>\u00a0Gold<\/strong><\/p>\n<ul>\n<li>Your program should be adapted so that stats for multiple players&#8217;s stats can be added.<\/li>\n<li>Your program should give the user to option to select which player&#8217;s stat sheet should be printed out.<\/li>\n<\/ul>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Youtube Blocked? Here are the videos on Google Drive instead Counter Example Dictionaries are often used as counters to keep a tally of items. Here is a simple example to show you how it works. Script Examples Here are a few live script examples to have a play with to see what Dictionaries could be&hellip;&nbsp;<a href=\"https:\/\/learnlearn.uk\/python\/dictionaries\/\" class=\"\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">Dictionaries<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"on","neve_meta_content_width":83,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Dictionaries - Python<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/learnlearn.uk\/python\/dictionaries\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Dictionaries - Python\" \/>\n<meta property=\"og:description\" content=\"Youtube Blocked? Here are the videos on Google Drive instead Counter Example Dictionaries are often used as counters to keep a tally of items. Here is a simple example to show you how it works. Script Examples Here are a few live script examples to have a play with to see what Dictionaries could be&hellip;&nbsp;Read More &raquo;Dictionaries\" \/>\n<meta property=\"og:url\" content=\"https:\/\/learnlearn.uk\/python\/dictionaries\/\" \/>\n<meta property=\"og:site_name\" content=\"Python\" \/>\n<meta property=\"article:modified_time\" content=\"2025-01-12T11:33:33+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2016\/01\/dictionary-300x200.jpg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/learnlearn.uk\/python\/dictionaries\/\",\"url\":\"https:\/\/learnlearn.uk\/python\/dictionaries\/\",\"name\":\"Dictionaries - Python\",\"isPartOf\":{\"@id\":\"https:\/\/learnlearn.uk\/python\/#website\"},\"datePublished\":\"2016-01-09T10:01:03+00:00\",\"dateModified\":\"2025-01-12T11:33:33+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/learnlearn.uk\/python\/dictionaries\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/learnlearn.uk\/python\/dictionaries\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/learnlearn.uk\/python\/dictionaries\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Python Unit Home\",\"item\":\"https:\/\/learnlearn.uk\/python\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Dictionaries\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/learnlearn.uk\/python\/#website\",\"url\":\"https:\/\/learnlearn.uk\/python\/\",\"name\":\"Python\",\"description\":\"Programming\",\"publisher\":{\"@id\":\"https:\/\/learnlearn.uk\/python\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/learnlearn.uk\/python\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/learnlearn.uk\/python\/#organization\",\"name\":\"Python\",\"url\":\"https:\/\/learnlearn.uk\/python\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/learnlearn.uk\/python\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2019\/03\/LearnLearnLogowhite.png\",\"contentUrl\":\"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2019\/03\/LearnLearnLogowhite.png\",\"width\":710,\"height\":98,\"caption\":\"Python\"},\"image\":{\"@id\":\"https:\/\/learnlearn.uk\/python\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Dictionaries - Python","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:\/\/learnlearn.uk\/python\/dictionaries\/","og_locale":"en_GB","og_type":"article","og_title":"Dictionaries - Python","og_description":"Youtube Blocked? Here are the videos on Google Drive instead Counter Example Dictionaries are often used as counters to keep a tally of items. Here is a simple example to show you how it works. Script Examples Here are a few live script examples to have a play with to see what Dictionaries could be&hellip;&nbsp;Read More &raquo;Dictionaries","og_url":"https:\/\/learnlearn.uk\/python\/dictionaries\/","og_site_name":"Python","article_modified_time":"2025-01-12T11:33:33+00:00","og_image":[{"url":"http:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2016\/01\/dictionary-300x200.jpg"}],"twitter_card":"summary_large_image","twitter_misc":{"Estimated reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/learnlearn.uk\/python\/dictionaries\/","url":"https:\/\/learnlearn.uk\/python\/dictionaries\/","name":"Dictionaries - Python","isPartOf":{"@id":"https:\/\/learnlearn.uk\/python\/#website"},"datePublished":"2016-01-09T10:01:03+00:00","dateModified":"2025-01-12T11:33:33+00:00","breadcrumb":{"@id":"https:\/\/learnlearn.uk\/python\/dictionaries\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/learnlearn.uk\/python\/dictionaries\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/learnlearn.uk\/python\/dictionaries\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Python Unit Home","item":"https:\/\/learnlearn.uk\/python\/"},{"@type":"ListItem","position":2,"name":"Dictionaries"}]},{"@type":"WebSite","@id":"https:\/\/learnlearn.uk\/python\/#website","url":"https:\/\/learnlearn.uk\/python\/","name":"Python","description":"Programming","publisher":{"@id":"https:\/\/learnlearn.uk\/python\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/learnlearn.uk\/python\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-GB"},{"@type":"Organization","@id":"https:\/\/learnlearn.uk\/python\/#organization","name":"Python","url":"https:\/\/learnlearn.uk\/python\/","logo":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/learnlearn.uk\/python\/#\/schema\/logo\/image\/","url":"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2019\/03\/LearnLearnLogowhite.png","contentUrl":"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2019\/03\/LearnLearnLogowhite.png","width":710,"height":98,"caption":"Python"},"image":{"@id":"https:\/\/learnlearn.uk\/python\/#\/schema\/logo\/image\/"}}]}},"rttpg_featured_image_url":null,"rttpg_author":{"display_name":"learnlearnadmin","author_link":"https:\/\/learnlearn.uk\/python\/author\/learnlearnadmin\/"},"rttpg_comment":0,"rttpg_category":null,"rttpg_excerpt":"Youtube Blocked? Here are the videos on Google Drive instead Counter Example Dictionaries are often used as counters to keep a tally of items. Here is a simple example to show you how it works. Script Examples Here are a few live script examples to have a play with to see what Dictionaries could be&hellip;&nbsp;Read&hellip;","_links":{"self":[{"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/pages\/241"}],"collection":[{"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/comments?post=241"}],"version-history":[{"count":8,"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/pages\/241\/revisions"}],"predecessor-version":[{"id":1496,"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/pages\/241\/revisions\/1496"}],"wp:attachment":[{"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/media?parent=241"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}