{
    "componentChunkName": "component---src-templates-course-content-template-js",
    "path": "/part-5/3-grouping-and-structured-records/",
    "result": {"data":{"page":{"htmlAst":{"type":"element","tagName":"div","properties":{},"children":[{"type":"element","tagName":"text-box","properties":{"variant":"learningObjectives","name":"Learning objectives"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"After this section"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"You will be able to use dictionaries for frequency counts and grouping"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"You will be able to model similarly shaped records as a list of dictionaries"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"You will be able to filter structured records"}]},{"type":"text","value":"\n"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Part 4 introduced dictionary construction, lookup by key, traversal with "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"items()"}]},{"type":"text","value":", and lists of record dictionaries. This section applies those structures to grouping observations and maintaining small collections of records."}]},{"type":"element","tagName":"h2","properties":{"id":"grouping-and-counting","style":"position:relative;"},"children":[{"type":"text","value":"Grouping and counting"},{"type":"element","tagName":"a","properties":{"href":"#grouping-and-counting","ariaLabel":"grouping and counting permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Let's have a look at a list of words:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"word_list "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"text","value":"\n  "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"banana\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"milk\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"beer\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"cheese\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"sourmilk\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"juice\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"sausage\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":"\n  "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"tomato\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"cucumber\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"butter\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"margarine\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"cheese\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"sausage\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":"\n  "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"beer\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"sourmilk\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"sourmilk\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"butter\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"beer\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"chocolate\""}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"We would like to analyze this list of words in different ways. For instance, we would like to know how many times each word appears in the list."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"A dictionary can be a useful tool in managing this kind of information. In the example below, we go through the items in the list one by one. Using the words in the list as keys in a new dictionary, the value mapped to each key is the number of times the word has appeared:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"counts"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"my_list"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n    words "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]},{"type":"text","value":"\n    "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" word "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" my_list"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n        "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# if the word is not yet in the dictionary, initialize the value to zero"}]},{"type":"text","value":"\n        "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" word "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"not"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" words"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n            words"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"text","value":"word"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"text","value":"\n        "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# increment the value"}]},{"type":"text","value":"\n        words"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"text","value":"word"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"+="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"text","value":"\n    "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" words\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# call the function"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"counts"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"word_list"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The program prints out the following:"}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"{'banana': 1, 'milk': 1, 'beer': 3, 'cheese': 2, 'sourmilk': 3, 'juice': 1, 'sausage': 2, 'tomato': 1, 'cucumber': 1, 'butter': 2, 'margarine': 1, 'chocolate': 1}"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"What if we wanted to categorize the words based on the initial letter in each word? One way to accomplish this would be to use dictionaries:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"def"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"categorize_by_initial"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"my_list"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n    groups "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]},{"type":"text","value":"\n    "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" word "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" my_list"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n        initial "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" word"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n        "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# initialize a new list when the letter is first encountered"}]},{"type":"text","value":"\n        "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" initial "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"not"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" groups"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n            groups"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"text","value":"initial"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n        "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"# add the word to the appropriate list"}]},{"type":"text","value":"\n        groups"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"text","value":"initial"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"append"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"word"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n    "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" groups\n\ngroups "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" categorize_by_initial"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"word_list"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" key"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" value "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" groups"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"items"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n    "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string-interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"f\"words beginning with "}]},{"type":"element","tagName":"span","properties":{"className":["token","interpolation"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"key"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":":\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n    "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" word "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"in"}]},{"type":"text","value":" value"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":"\n        "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"word"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The structure of the function is very similar to the previous exercise but this time the values mapped to the keys are lists. The program prints out the following:"}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"words beginning with b:\nbanana\nbeer\nbutter\nbeer\nbutter\nbeer\nwords beginning with m:\nmilk\nmargarine\nwords beginning with c:\ncheese\ncucumber\ncheese\nchocolate\nwords beginning with s:\nsourmilk\nsausage\nsausage\nsourmilk\nsourmilk\nwords beginning with j:\njuice\nwords beginning with t:\ntomato"}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Histogram","tmcname":"part05-16_histogram"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Mode: Independent practice"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Please write a function named "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"histogram"}]},{"type":"text","value":", which takes a string as its argument. The function should print out a histogram representing the number of times each letter occurs in the string. Each occurrence of a letter should be represented by a star on the specific line for that letter."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"For example, the function call "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"histogram(\"abba\")"}]},{"type":"text","value":" should print out"}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"pre","properties":{},"children":[{"type":"text","value":"a **\nb **\n"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"while "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"histogram(\"statistically\")"}]},{"type":"text","value":" should print out"}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"pre","properties":{},"children":[{"type":"text","value":"s **\nt ***\na **\ni **\nc *\nl **\ny *\n"}]}]}]},{"type":"element","tagName":"h2","properties":{"id":"structured-records-in-practice","style":"position:relative;"},"children":[{"type":"text","value":"Structured records in practice"},{"type":"element","tagName":"a","properties":{"href":"#structured-records-in-practice","ariaLabel":"structured records in practice permalink","className":["anchor","after"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"A list of dictionaries is useful when each record has the same named fields. The following exercises apply the record shape introduced in Part 4: first by adding complete records to a collection, and then by filtering that collection. Focus on preserving the agreed field names and returning records in their original shape."}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Movie database","tmcname":"part05-21_movie_database"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Mode: Code review and repair"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Pipeline stage(s): Transform"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The starter contains a function named "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"add_movie(database: list, name: str, director: str, year: int, runtime: int)"}]},{"type":"text","value":", which adds a new movie record to a database. The function runs without raising an error, but the new record does not follow the complete data contract described below."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Before editing, call the function and compare the keys of the new record against the four required keys listed below. Then repair the function without replacing the database or discarding records which were already there."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The database is a list, and each movie object in the list is a dictionary. The dictionary should contain the following keys."}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"name"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"director"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"year"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"runtime"}]},{"type":"text","value":"\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The values attached to these keys are given as arguments to the function."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"An example of its use:"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"database "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\nadd_movie"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"database"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Gone with the Python\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Victor Pything\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2017"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"116"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\nadd_movie"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"database"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Pythons on a Plane\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Renny Pytholin\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2001"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"94"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"database"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"[{\"name\": \"Gone with the Python\", \"director\": \"Victor Pything\", \"year\": 2017, \"runtime\": 116}, {\"name\": \"Pythons on a Plane\", \"director\": \"Renny Pytholin\", \"year\": 2001, \"runtime\": 94}]"}]}]}]},{"type":"element","tagName":"programming-exercise","properties":{"name":"Find movies by genre","tmcname":"part05-22_find_movies"},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Mode: Agent-assisted change"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Pipeline stage(s): Validate, Transform"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The starter contains a working "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"find_movies"}]},{"type":"text","value":" function which searches movie names. The requirements have now changed: every movie record has a "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"genres"}]},{"type":"text","value":" field containing a list of strings, and users need to filter by genre instead."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Change the function into "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"find_movies_by_genre(database: list, genre: str)"}]},{"type":"text","value":". It should return every movie whose "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"genres"}]},{"type":"text","value":" list contains the requested genre. Matching is case-insensitive, the source order is preserved, and the database and its records are not changed."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Use the agent-assisted workflow:"}]},{"type":"element","tagName":"ol","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Specify the new record shapes and the filtering contract."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Ask an agent first for the smallest exact-case genre search. Inspect which nested collection its condition traverses and verify a movie with multiple genres and a genre with no matches."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Add the changed requirement yourself: make the genre comparison case-insensitive without changing the stored strings or returned records."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Add a mixed-case assertion which would have failed for the agent's first version, then check that the source records remain unchanged."}]},{"type":"text","value":"\n"}]},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"python"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-python"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-python"]},"children":[{"type":"text","value":"database "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"text","value":"\n  "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"name\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Archive Nights\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"director\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"A. Example\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"year\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2017"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":"\n   "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"runtime\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"96"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"genres\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Documentary\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"History\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":"\n  "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"name\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Signal\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"director\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"B. Example\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"year\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2021"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":"\n   "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"runtime\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"104"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"genres\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Drama\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":"\n  "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"name\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Painted Lives\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"director\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"C. Example\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"year\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"2019"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":"\n   "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"runtime\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"88"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"genres\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Documentary\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Art\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":"\n\nmy_movies "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" find_movies_by_genre"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"database"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"documentary\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"print"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"my_movies"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"sample-output","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"[{'name': 'Archive Nights', 'director': 'A. Example', 'year': 2017, 'runtime': 96, 'genres': ['Documentary', 'History']}, {'name': 'Painted Lives', 'director': 'C. Example', 'year': 2019, 'runtime': 88, 'genres': ['Documentary', 'Art']}]"}]}]}]},{"type":"comment","value":"-\nA quiz to review the contents of this section:\n\n<quiz id=\"6361eeca-a2e2-5577-892c-749706d754f0\"></quiz>\n"}]},"html":"<div><text-box variant='learningObjectives' name=\"Learning objectives\"><p>After this section</p><ul>\n<li>You will be able to use dictionaries for frequency counts and grouping</li>\n<li>You will be able to model similarly shaped records as a list of dictionaries</li>\n<li>You will be able to filter structured records</li>\n</ul></text-box><p>Part 4 introduced dictionary construction, lookup by key, traversal with <code class=\"language-text\">items()</code>, and lists of record dictionaries. This section applies those structures to grouping observations and maintaining small collections of records.</p><h2 id=\"grouping-and-counting\" style=\"position:relative;\">Grouping and counting<a href=\"#grouping-and-counting\" aria-label=\"grouping and counting permalink\" class=\"anchor after\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a></h2><p>Let's have a look at a list of words:</p><div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">word_list <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>\n  <span class=\"token string\">\"banana\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"milk\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"beer\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"cheese\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"sourmilk\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"juice\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"sausage\"</span><span class=\"token punctuation\">,</span>\n  <span class=\"token string\">\"tomato\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"cucumber\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"butter\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"margarine\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"cheese\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"sausage\"</span><span class=\"token punctuation\">,</span>\n  <span class=\"token string\">\"beer\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"sourmilk\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"sourmilk\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"butter\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"beer\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"chocolate\"</span>\n<span class=\"token punctuation\">]</span></code></pre></div><p>We would like to analyze this list of words in different ways. For instance, we would like to know how many times each word appears in the list.</p><p>A dictionary can be a useful tool in managing this kind of information. In the example below, we go through the items in the list one by one. Using the words in the list as keys in a new dictionary, the value mapped to each key is the number of times the word has appeared:</p><div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">counts</span><span class=\"token punctuation\">(</span>my_list<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    words <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">for</span> word <span class=\"token keyword\">in</span> my_list<span class=\"token punctuation\">:</span>\n        <span class=\"token comment\"># if the word is not yet in the dictionary, initialize the value to zero</span>\n        <span class=\"token keyword\">if</span> word <span class=\"token keyword\">not</span> <span class=\"token keyword\">in</span> words<span class=\"token punctuation\">:</span>\n            words<span class=\"token punctuation\">[</span>word<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token number\">0</span>\n        <span class=\"token comment\"># increment the value</span>\n        words<span class=\"token punctuation\">[</span>word<span class=\"token punctuation\">]</span> <span class=\"token operator\">+=</span> <span class=\"token number\">1</span>\n    <span class=\"token keyword\">return</span> words\n\n<span class=\"token comment\"># call the function</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>counts<span class=\"token punctuation\">(</span>word_list<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div><p>The program prints out the following:</p><sample-output><p>{'banana': 1, 'milk': 1, 'beer': 3, 'cheese': 2, 'sourmilk': 3, 'juice': 1, 'sausage': 2, 'tomato': 1, 'cucumber': 1, 'butter': 2, 'margarine': 1, 'chocolate': 1}</p></sample-output><p>What if we wanted to categorize the words based on the initial letter in each word? One way to accomplish this would be to use dictionaries:</p><div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">categorize_by_initial</span><span class=\"token punctuation\">(</span>my_list<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    groups <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">for</span> word <span class=\"token keyword\">in</span> my_list<span class=\"token punctuation\">:</span>\n        initial <span class=\"token operator\">=</span> word<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span>\n        <span class=\"token comment\"># initialize a new list when the letter is first encountered</span>\n        <span class=\"token keyword\">if</span> initial <span class=\"token keyword\">not</span> <span class=\"token keyword\">in</span> groups<span class=\"token punctuation\">:</span>\n            groups<span class=\"token punctuation\">[</span>initial<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span>\n        <span class=\"token comment\"># add the word to the appropriate list</span>\n        groups<span class=\"token punctuation\">[</span>initial<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span>word<span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">return</span> groups\n\ngroups <span class=\"token operator\">=</span> categorize_by_initial<span class=\"token punctuation\">(</span>word_list<span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">for</span> key<span class=\"token punctuation\">,</span> value <span class=\"token keyword\">in</span> groups<span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"words beginning with </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>key<span class=\"token punctuation\">}</span></span><span class=\"token string\">:\"</span></span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">for</span> word <span class=\"token keyword\">in</span> value<span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>word<span class=\"token punctuation\">)</span></code></pre></div><p>The structure of the function is very similar to the previous exercise but this time the values mapped to the keys are lists. The program prints out the following:</p><sample-output><p>words beginning with b:\nbanana\nbeer\nbutter\nbeer\nbutter\nbeer\nwords beginning with m:\nmilk\nmargarine\nwords beginning with c:\ncheese\ncucumber\ncheese\nchocolate\nwords beginning with s:\nsourmilk\nsausage\nsausage\nsourmilk\nsourmilk\nwords beginning with j:\njuice\nwords beginning with t:\ntomato</p></sample-output><programming-exercise name='Histogram' tmcname='part05-16_histogram'><p><strong>Mode: Independent practice</strong></p><p>Please write a function named <code class=\"language-text\">histogram</code>, which takes a string as its argument. The function should print out a histogram representing the number of times each letter occurs in the string. Each occurrence of a letter should be represented by a star on the specific line for that letter.</p><p>For example, the function call <code class=\"language-text\">histogram(\"abba\")</code> should print out</p><sample-output><pre>\na **\nb **\n</pre></sample-output><p>while <code class=\"language-text\">histogram(\"statistically\")</code> should print out</p><sample-output><pre>\ns **\nt ***\na **\ni **\nc *\nl **\ny *\n</pre></sample-output></programming-exercise><h2 id=\"structured-records-in-practice\" style=\"position:relative;\">Structured records in practice<a href=\"#structured-records-in-practice\" aria-label=\"structured records in practice permalink\" class=\"anchor after\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a></h2><p>A list of dictionaries is useful when each record has the same named fields. The following exercises apply the record shape introduced in Part 4: first by adding complete records to a collection, and then by filtering that collection. Focus on preserving the agreed field names and returning records in their original shape.</p><programming-exercise name='Movie database' tmcname='part05-21_movie_database'><p><strong>Mode: Code review and repair</strong></p><p><strong>Pipeline stage(s): Transform</strong></p><p>The starter contains a function named <code class=\"language-text\">add_movie(database: list, name: str, director: str, year: int, runtime: int)</code>, which adds a new movie record to a database. The function runs without raising an error, but the new record does not follow the complete data contract described below.</p><p>Before editing, call the function and compare the keys of the new record against the four required keys listed below. Then repair the function without replacing the database or discarding records which were already there.</p><p>The database is a list, and each movie object in the list is a dictionary. The dictionary should contain the following keys.</p><ul>\n<li>name</li>\n<li>director</li>\n<li>year</li>\n<li>runtime</li>\n</ul><p>The values attached to these keys are given as arguments to the function.</p><p>An example of its use:</p><div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">database <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span>\nadd_movie<span class=\"token punctuation\">(</span>database<span class=\"token punctuation\">,</span> <span class=\"token string\">\"Gone with the Python\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Victor Pything\"</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2017</span><span class=\"token punctuation\">,</span> <span class=\"token number\">116</span><span class=\"token punctuation\">)</span>\nadd_movie<span class=\"token punctuation\">(</span>database<span class=\"token punctuation\">,</span> <span class=\"token string\">\"Pythons on a Plane\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Renny Pytholin\"</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2001</span><span class=\"token punctuation\">,</span> <span class=\"token number\">94</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>database<span class=\"token punctuation\">)</span></code></pre></div><sample-output><p>[{\"name\": \"Gone with the Python\", \"director\": \"Victor Pything\", \"year\": 2017, \"runtime\": 116}, {\"name\": \"Pythons on a Plane\", \"director\": \"Renny Pytholin\", \"year\": 2001, \"runtime\": 94}]</p></sample-output></programming-exercise><programming-exercise name='Find movies by genre' tmcname='part05-22_find_movies'><p><strong>Mode: Agent-assisted change</strong></p><p><strong>Pipeline stage(s): Validate, Transform</strong></p><p>The starter contains a working <code class=\"language-text\">find_movies</code> function which searches movie names. The requirements have now changed: every movie record has a <code class=\"language-text\">genres</code> field containing a list of strings, and users need to filter by genre instead.</p><p>Change the function into <code class=\"language-text\">find_movies_by_genre(database: list, genre: str)</code>. It should return every movie whose <code class=\"language-text\">genres</code> list contains the requested genre. Matching is case-insensitive, the source order is preserved, and the database and its records are not changed.</p><p>Use the agent-assisted workflow:</p><ol>\n<li>Specify the new record shapes and the filtering contract.</li>\n<li>Ask an agent first for the smallest exact-case genre search. Inspect which nested collection its condition traverses and verify a movie with multiple genres and a genre with no matches.</li>\n<li>Add the changed requirement yourself: make the genre comparison case-insensitive without changing the stored strings or returned records.</li>\n<li>Add a mixed-case assertion which would have failed for the agent's first version, then check that the source records remain unchanged.</li>\n</ol><div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">database <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>\n  <span class=\"token punctuation\">{</span><span class=\"token string\">\"name\"</span><span class=\"token punctuation\">:</span> <span class=\"token string\">\"Archive Nights\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"director\"</span><span class=\"token punctuation\">:</span> <span class=\"token string\">\"A. Example\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"year\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">2017</span><span class=\"token punctuation\">,</span>\n   <span class=\"token string\">\"runtime\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">96</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"genres\"</span><span class=\"token punctuation\">:</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"Documentary\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"History\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">{</span><span class=\"token string\">\"name\"</span><span class=\"token punctuation\">:</span> <span class=\"token string\">\"Signal\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"director\"</span><span class=\"token punctuation\">:</span> <span class=\"token string\">\"B. Example\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"year\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">2021</span><span class=\"token punctuation\">,</span>\n   <span class=\"token string\">\"runtime\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">104</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"genres\"</span><span class=\"token punctuation\">:</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"Drama\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">{</span><span class=\"token string\">\"name\"</span><span class=\"token punctuation\">:</span> <span class=\"token string\">\"Painted Lives\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"director\"</span><span class=\"token punctuation\">:</span> <span class=\"token string\">\"C. Example\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"year\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">2019</span><span class=\"token punctuation\">,</span>\n   <span class=\"token string\">\"runtime\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">88</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"genres\"</span><span class=\"token punctuation\">:</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"Documentary\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Art\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">]</span>\n\nmy_movies <span class=\"token operator\">=</span> find_movies_by_genre<span class=\"token punctuation\">(</span>database<span class=\"token punctuation\">,</span> <span class=\"token string\">\"documentary\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>my_movies<span class=\"token punctuation\">)</span></code></pre></div><sample-output><p>[{'name': 'Archive Nights', 'director': 'A. Example', 'year': 2017, 'runtime': 96, 'genres': ['Documentary', 'History']}, {'name': 'Painted Lives', 'director': 'C. Example', 'year': 2019, 'runtime': 88, 'genres': ['Documentary', 'Art']}]</p></sample-output></programming-exercise><!---\nA quiz to review the contents of this section:\n\n<quiz id=\"6361eeca-a2e2-5577-892c-749706d754f0\"></quiz>\n--></div>","frontmatter":{"path":"/part-5/3-grouping-and-structured-records/","title":"Grouping and structured records"},"fileAbsolutePath":"/home/runner/work/programming-digital-humanities/programming-digital-humanities/data/part-5/3-grouping-and-structured-records.md"},"allPages":{"edges":[{"node":{"id":"5d899565-03f0-55ea-8073-4ee194950c4d","frontmatter":{"path":"/ai-tutor/","title":"Using the AI tutor on the course"}}},{"node":{"id":"c6198176-c061-5cca-a182-cc80cdb14e38","frontmatter":{"path":"/all-exercises/","title":"All exercises"}}},{"node":{"id":"6c2bb78f-1497-5d72-a964-8cb55e47559e","frontmatter":{"path":"/error_messages/","title":"Common error messages"}}},{"node":{"id":"96430bcf-4526-5d85-9206-c7336a6be270","frontmatter":{"path":"/faq/","title":"Frequently asked questions"}}},{"node":{"id":"0d6f8da4-7d4f-5228-a832-7ff574e63570","frontmatter":{"path":"/frontmatter-guide","title":"Frontmatter-guide"}}},{"node":{"id":"249c8a64-20fb-510c-8b3e-f5b3b72fe028","frontmatter":{"path":"/grading/","title":"Grading"}}},{"node":{"id":"5b5e6522-0d23-577b-9ba9-4ecd1c1c5d24","frontmatter":{"path":"/","title":"About this course"}}},{"node":{"id":"bcdb2bdc-e92c-5c75-8dd1-13f57e1129da","frontmatter":{"path":"/glossary","title":"Glossary"}}},{"node":{"id":"d54c2afb-004d-500e-9d19-aa3d154a39a5","frontmatter":{"path":"/part-0/","title":"Part 0: See what an agent can build"}}},{"node":{"id":"fff8e65b-0281-55fe-a21a-9e7e872ddc33","frontmatter":{"path":"/part-1/1-getting-started/","title":"Getting started"}}},{"node":{"id":"9fa0a7fc-c673-56ad-9dc8-bf6aeb6d3b05","frontmatter":{"path":"/part-1/2-information-from-the-user/","title":"Information from the user"}}},{"node":{"id":"c2286d4a-4cf7-5fc4-ab0f-f7cd2acf49df","frontmatter":{"path":"/part-1/3-more-about-variables/","title":"More about variables"}}},{"node":{"id":"3ebadf79-0e16-5ed7-bcb2-bec3731cffc2","frontmatter":{"path":"/part-1/4-arithmetic-operations/","title":"Arithmetic operations"}}},{"node":{"id":"c77004ff-fe4d-5533-b77f-c861fa42430d","frontmatter":{"path":"/part-1/5-conditional-statements/","title":"Conditional statements"}}},{"node":{"id":"50ee91dc-7fe8-508d-940f-577449a335f4","frontmatter":{"path":"/part-1/","title":"Part 1"}}},{"node":{"id":"d963c6b4-b2d4-59ff-b310-265b28e2c8d2","frontmatter":{"path":"/part-2/1-programming-terminology/","title":"Programming terminology"}}},{"node":{"id":"075f597d-a49f-59c1-ad1a-d68ba19aa0f4","frontmatter":{"path":"/part-2/2-else-elif/","title":"More conditionals"}}},{"node":{"id":"26776fa9-27c7-5554-990b-09d6661a07a8","frontmatter":{"path":"/part-2/3-combining-conditions/","title":"Combining conditions"}}},{"node":{"id":"1da4e234-e81f-5494-b2d4-96e30cbb4464","frontmatter":{"path":"/part-2/4-simple-loops/","title":"Simple loops"}}},{"node":{"id":"db78d781-f405-5904-91bf-e96f7f04353f","frontmatter":{"path":"/part-2/","title":"Part 2"}}},{"node":{"id":"10808e92-b68f-58c3-b767-cf5e9c0efeb7","frontmatter":{"path":"/part-3/1-loops-with-conditions/","title":"Loops with conditions"}}},{"node":{"id":"bceed420-a129-52a7-81ed-dafd67ad38df","frontmatter":{"path":"/part-3/2-working-with-strings/","title":"Working with strings"}}},{"node":{"id":"e2dfd9d3-07fa-59a0-b748-370355606256","frontmatter":{"path":"/part-3/3-more-loops/","title":"More loops"}}},{"node":{"id":"5b546d28-ac00-564f-9d75-cc09c4382b64","frontmatter":{"path":"/part-3/4-defining-functions/","title":"Defining functions"}}},{"node":{"id":"12122cff-c09e-53f1-8b76-8517f845e08c","frontmatter":{"path":"/part-3/","title":"Part 3"}}},{"node":{"id":"8fbb5845-152f-5be7-ac92-fa280093b2a2","frontmatter":{"path":"/part-4/1-vscode/","title":"The Visual Studio Code editor, Python interpreter and built-in debugging tool"}}},{"node":{"id":"b8d090a9-7e49-5ab7-a5a1-d126179dd9a0","frontmatter":{"path":"/part-4/2-more-functions/","title":"More functions"}}},{"node":{"id":"271308ca-b267-5c86-8051-8a1a3480cfcb","frontmatter":{"path":"/part-4/3-lists/","title":"Lists"}}},{"node":{"id":"e5a8fd16-890d-509e-9666-9c622648c18a","frontmatter":{"path":"/part-4/4-definite-iteration/","title":"Definite iteration"}}},{"node":{"id":"ca4caea3-eaad-5cc3-a1fa-83b9bb90a25e","frontmatter":{"path":"/part-4/5-strings-and-lists/","title":"More strings and lists"}}},{"node":{"id":"adeebce2-76be-5528-90a1-6feaa066fcd8","frontmatter":{"path":"/part-4/6-data-structures/","title":"Data structures and data shapes"}}},{"node":{"id":"07e761ca-39a1-50a1-97d8-9149e4737e89","frontmatter":{"path":"/part-4/","title":"Part 4"}}},{"node":{"id":"80fe5d23-31eb-5ff6-b339-99e173e9279f","frontmatter":{"path":"/part-5/0-working-with-ai/","title":"Working with AI from Part 5 onward"}}},{"node":{"id":"111a6af4-b8a7-5d71-8966-f750f6c161a6","frontmatter":{"path":"/part-5/1-tables-as-nested-lists/","title":"Tables as nested lists"}}},{"node":{"id":"7e2cf429-03ea-5e8c-86ce-62c71c689a75","frontmatter":{"path":"/part-5/2-references/","title":"References and transformed results"}}},{"node":{"id":"3901dc36-3116-5444-9120-6b38454e245f","frontmatter":{"path":"/part-5/3-grouping-and-structured-records/","title":"Grouping and structured records"}}},{"node":{"id":"076a1db2-8d62-5725-ad72-c43ea25897c6","frontmatter":{"path":"/part-5/4-small-database/","title":"Building a small database"}}},{"node":{"id":"cf823ebf-3d67-53ca-8fcf-9b53fee10c1d","frontmatter":{"path":"/part-5/5-in-memory-analysis-pipeline/","title":"An in-memory analysis pipeline"}}},{"node":{"id":"92cbc670-d401-53b8-949f-9725b81a5e4a","frontmatter":{"path":"/part-5/","title":"Part 5"}}},{"node":{"id":"52ecf5a7-9266-58c8-bac5-407b1a29a9dd","frontmatter":{"path":"/part-6/2-writing-files/","title":"Writing and exporting files"}}},{"node":{"id":"a296984d-7503-558e-86da-ddb801f8a59b","frontmatter":{"path":"/part-6/3-scope-of-variables/","title":"Make data flow explicit"}}},{"node":{"id":"98bdbc42-0ebc-5f9c-b767-b987266a0040","frontmatter":{"path":"/part-6/4-modules/","title":"Use existing libraries"}}},{"node":{"id":"0ca5c730-bd8e-5099-9768-8fcb8eb0b7b4","frontmatter":{"path":"/part-6/1-reading-files/","title":"Reading files"}}},{"node":{"id":"11759056-5a15-5820-a693-30f4df62f118","frontmatter":{"path":"/part-6/","title":"Part 6"}}},{"node":{"id":"6e748518-2c76-5428-8779-0f0455b17a0d","frontmatter":{"path":"/part-7/0-dataframes-and-views/","title":"Working with pandas dataframes"}}},{"node":{"id":"047a5114-7ebb-5a5c-8ed0-eadf81564546","frontmatter":{"path":"/part-7/1-times-and-dates/","title":"Times and dates"}}},{"node":{"id":"7cc9d1d2-fb68-52da-b5ec-034bf9f4585f","frontmatter":{"path":"/part-7/3-more-features/","title":"More Python features"}}},{"node":{"id":"5055044d-7938-5e5d-be5c-dfb0ff2c81b4","frontmatter":{"path":"/part-7/2-data-processing/","title":"Data processing"}}},{"node":{"id":"cea3f325-56bb-5a93-885e-275e465c1ced","frontmatter":{"path":"/part-7/","title":"Part 7"}}},{"node":{"id":"3abea309-839b-562f-bb00-3be40d963200","frontmatter":{"path":"/part-8/","title":"Part 8"}}}]}},"pageContext":{}},
    "staticQueryHashes": ["1357757885","994120085"]}