[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"doc-seo-685678-105":3,"detail-sidebar-cat-0-en-105":80,"doc-detail-685678-en":130,"doc-similar-685678":154},{"code":4,"msg":5,"data":6},0,"ok",{"site_id":7,"language":8,"slug":9,"title":10,"keywords":11,"description":12,"schema_data":13,"social_meta":73,"head_meta":75,"extra_data":77,"updated_unix":79},105,"en","python-lesson-5-dictionaries-and-json-error-trapping-lists-and-nesting","Python Lesson 5 - Dictionaries and JSON - Error Trapping, Lists, and Nesting","","Python Lesson 5 explains dictionaries as an unordered key-to-value data structure defined with curly braces, where values are retrieved by unique keys. It covers practical error handling using try/except for graceful exception management and highlights correct indentation and required colons. The lesson then shows how to store dictionaries in lists and access nested values, clarifying that key ordering has no significance. It concludes with JSON basics: key:value pairs, JSON objects, arrays, and nesting arrays inside objects for multiple options.",{"@graph":14,"@context":72},[15,34,55],{"@type":16,"itemListElement":17},"BreadcrumbList",[18,23,27,31],{"item":19,"name":20,"@type":21,"position":22},"https://docshare.wps.com","Home","ListItem",1,{"item":24,"name":25,"@type":21,"position":26},"https://docshare.wps.com/document/","Document",2,{"item":28,"name":29,"@type":21,"position":30},"https://docshare.wps.com/document/technology/","Technology",3,{"item":32,"name":10,"@type":21,"position":33},"https://docshare.wps.com/document/python-lesson-5-dictionaries-and-json-error-trapping-lists-and-nesting/685678/",4,{"url":32,"name":10,"@type":35,"image":36,"author":41,"headline":10,"publisher":44,"fileFormat":47,"inLanguage":8,"description":12,"dateModified":48,"datePublished":49,"encodingFormat":47,"isAccessibleForFree":50,"interactionStatistic":51},"DigitalDocument",{"url":37,"@type":38,"width":39,"height":40},"https://docshare.wps.com/thumbnails/python-lesson-5-dictionaries-and-json-error-trapping-lists-and-nesting/685678.png","ImageObject",300,407,{"name":42,"@type":43},"jayni","Person",{"url":19,"name":45,"@type":46},"DocShare","Organization","application/pdf","2026-11-12","2026-11-07",true,{"@type":52,"interactionType":53,"userInteractionCount":30},"InteractionCounter",{"@type":54},"ViewAction",{"@type":56,"mainEntity":57},"FAQPage",[58,64,68],{"name":59,"@type":60,"acceptedAnswer":61},"How do dictionaries work in this lesson?","Question",{"text":62,"@type":63},"Dictionaries store values identified by keys and are defined using curly braces {}. Values are accessed by looking up the key, and keys should be unique.","Answer",{"name":65,"@type":60,"acceptedAnswer":66},"What is the purpose of try...except in the lesson?",{"text":67,"@type":63},"try...except is used for error trapping so the program handles problems gracefully instead of crashing. Exceptions are managed by running code in the appropriate block.",{"name":69,"@type":60,"acceptedAnswer":70},"How is JSON structured according to the lesson?",{"text":71,"@type":63},"JSON uses key:value pairs as a basic unit, with strings in quotes and numbers without quotes. A JSON object places multiple key:value pairs inside curly brackets {}, and arrays are written inside square brackets [].","https://schema.org",{"og:url":32,"og:type":74,"og:title":10,"og:site_name":45,"og:description":12},"article",{"robots":76,"canonical":32},"index,follow",{"doc_id":78,"site_id":7},685678,1794016562,{"code":4,"msg":81,"data":82},"success",[83,87,91,95,100,104,109,114,119,122,126],{"id":22,"doc_module":4,"doc_module_name":25,"category_name":84,"show_sort_weight":85,"slug":86},"Story & Novel",90,"story-novel",{"id":26,"doc_module":4,"doc_module_name":25,"category_name":88,"show_sort_weight":89,"slug":90},"Literature",80,"literature",{"id":33,"doc_module":4,"doc_module_name":25,"category_name":92,"show_sort_weight":93,"slug":94},"Exam",70,"exam",{"id":96,"doc_module":4,"doc_module_name":25,"category_name":97,"show_sort_weight":98,"slug":99},5,"Comic",60,"comic",{"id":101,"doc_module":4,"doc_module_name":25,"category_name":29,"show_sort_weight":102,"slug":103},6,50,"technology",{"id":105,"doc_module":4,"doc_module_name":25,"category_name":106,"show_sort_weight":107,"slug":108},7,"Healthcare",40,"healthcare",{"id":110,"doc_module":4,"doc_module_name":25,"category_name":111,"show_sort_weight":112,"slug":113},8,"Research & Report",30,"research-report",{"id":115,"doc_module":4,"doc_module_name":25,"category_name":116,"show_sort_weight":117,"slug":118},9,"Religion & Spirituality",20,"religion-spirituality",{"id":117,"doc_module":4,"doc_module_name":25,"category_name":120,"show_sort_weight":117,"slug":121},"World Cup","world-cup",{"id":123,"doc_module":4,"doc_module_name":25,"category_name":124,"show_sort_weight":123,"slug":125},10,"Lifestyle","lifestyle",{"id":127,"doc_module":4,"doc_module_name":25,"category_name":128,"show_sort_weight":96,"slug":129},19,"General","general",{"code":4,"msg":81,"data":131},{"doc_id":78,"user_id":132,"nickname":42,"user_avatar":133,"doc_module":4,"category_id":101,"category_name":29,"doc_title":10,"doc_description":12,"doc_content":134,"file_id":135,"file_url":136,"file_type":137,"file_size":138,"view_count":30,"is_deleted":4,"is_public":22,"is_downloadable":22,"audit_status":22,"page_count":139,"language":140,"language_code":8,"site_id":7,"html_lang":8,"table_of_contents":141,"faqs":142,"seo_title":143,"seo_description":12,"update_tm":79,"read_time":144,"preview_page_count":26,"preview_urls":145},3985747859343,"https://ap-avatar.wpscdn.com/davatar_276721f389ce27ea32af1340a28f341c","Python Lesson 5: Dictionaries and JSON  \n[vanderbi.lt/py](vanderbi.lt/py)  \nSteve Baskauf  \nDictionaries  \n• Dictionaries are an unordered data structure.  \n• They're defined using curly brackets: {}  \n• Values are identified by keys.  \n• We \"look up\" values in the dictionary using the keys.  \ncompany = {'Mickey Mouse':'Disney', 'Donald Duck':'Disney', 'Daffy Duck':'Warner Brothers', 'Fred Flintstone':'Hanna Barbera'}  \nkey  \n'Mickey Mouse'  \nDonald Duck'  \nDaffy Duck'  \n'Fred Flintstone'  \nvalue  \n| 'Disney' |\n| --- |\n| 'Disney' |\n| 'Warner Brothers' |\n| 'Hanna Barbera' |\n\ncompany['Mickey Mouse']  \n company['Daffy Duck']  \nkey  \ntry…except… for error trapping  \ntry:  \ncode that might throw an error goes here  \nexcept:  \ncode to be executed if there's an error goes here here's where the code execution continues  \n• Error trapping handles problems gracefully instead of having the script crash.  \n• An error is called an exception.  \n• Code blocks are identified by indentation (as usual)  \n• Colons required after try and except  \ntry…except… for error trapping • Example:  \ntry:  \nprint('That character works for ' + company[characterName])  \nexcept:  \nprint(\"I don't know who that character works for.\") print(\"That's all folks!\")  \n• It's a good idea to error trap any error that can be predicted to happen sometime ( [e.g. fi](e.g. fi)le not found)  \nTry this  \n• Note: the keys in a dictionary should be unique  \n• It is typical for keys to either:  \n• be some kind of identifier for a thing (this example)  \n• be some kind of characteristic of the thing (next example)  \nLists of dictionaries  \ncharacters = [{'name':'Mickey Mouse', 'company':'Disney', 'gender':'male'} , {'name':'WALL-E', 'company':'Pixar', 'gender': 'neutral'} ,{'name':'Fiona', 'company':'DreamWorks', 'gender': 'female'} ]  \ncharacters[0]['name']  \ncharacters[0]['gender']  \n'name': 'company': 'gender':  \n| {'name':'Mickey Mouse','company':'Disney','gender': 'male'} |\n| --- |\n| {'name':'WALL-E','company':'Pixar','gender': 'neutral'} |\n| {'name':'Fiona','company':'DreamWorks','gender': 'female'} |\n\n characters[0]  \n characters[1]  \n characters[2]  \n| 'Mickey Mouse' 'Disney' 'male' |\n| --- |\n| 'WALL-E' 'Pixar' 'neutral' |\n| 'Fiona' 'DreamWorks' 'female' |\n\nYou can think of this like:  \ndata[row][key]  \ncharacters[1]['company']  \ncharacters[2]['gender']  \nSince the keys aren't ordered, there is no significance to the location of the columns.  \nLists of dictionaries (cont.)  \n• Lists are iterable. Dictionaries aren't (they are unordered) .  \n• It's common for each item on the list to represent an individual of some category of thing and each key:value pair in that individual's dictionary to represent a property of that individual.  \n• Stepping through the list processes each individual.  \nExamples  \nWhat is JSON?  \n• A basic unit of JSON is a key:value pair. For example:\"name\":\"Steve\" (strings must be in quotes)\"fingers\":10 (numbers don't need quotes)  \n• A JSON object is a list of key:value pairs inside curly brackets.  \n{\"name\":\"Steve\", \"fingers\":10,  \n\"street\":\"Penny Lane\"}  \n• Multiple values can be put in an array inside square brackets.  \n[\"Steve\",\"Steven\",\"Esteban\"]  \nNesting in JSON  \n• Arrays can be nested inside objects  \n{  \n\"name\":  \n[  \n\"Steve\",  \n\"Steven\",  \n\"Esteban\"  \n],  \n\"fingers\":10,  \n\"street\":\"Penny Lane\"  \n}  \n• We use this when there are multiple options for a value  \n• In this example, the array holds multiple name values.","cbCaisxJoJ06preS","https://ap.wps.com/l/cbCaisxJoJ06preS","pdf",314868,18,"English","# Dictionaries\n## Dictionary basics (unordered, curly braces, keys)\n## Error trapping with try/except\n## Lists of dictionaries\n# JSON\n## What is JSON (key:value pairs)\n## JSON objects and arrays\n## Nesting in JSON (arrays inside objects)","[{\"question\":\"How do dictionaries work in this lesson?\",\"answer\":\"Dictionaries store values identified by keys and are defined using curly braces {}. Values are accessed by looking up the key, and keys should be unique.\"},{\"question\":\"What is the purpose of try...except in the lesson?\",\"answer\":\"try...except is used for error trapping so the program handles problems gracefully instead of crashing. Exceptions are managed by running code in the appropriate block.\"},{\"question\":\"How is JSON structured according to the lesson?\",\"answer\":\"JSON uses key:value pairs as a basic unit, with strings in quotes and numbers without quotes. A JSON object places multiple key:value pairs inside curly brackets {}, and arrays are written inside square brackets [].\"}]","Python Lesson 5 - Dictionaries and JSON - Error Trapping, Lists, and Nesting | PDF",45,[146,150],{"page_no":22,"url":147,"width":148,"height":149},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/ef9b6ed069d2272f6b288c4d5608e486.webp",983,737,{"page_no":26,"url":151,"width":152,"height":153},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/8058f8ce9d25e0026cb8d1fe8f1e9d80.webp",982,736,{"list":155,"token":11},[156,162,168,174,180,187,194,200,206,212],{"doc_id":157,"doc_title":158,"file_type":137,"home_preview_img_url":159,"slug":160,"view_count":33,"category_name":29,"create_tm":161},685680,"ECMA-404 - The JSON Data Interchange Syntax - 2nd Edition - December 2017","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000176288/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796110559&Signature=WSFuzdGk0iYYAYi6QqkoBcfmxzA%3D","ecma-404-the-json-data-interchange-syntax-2nd-edition-december-2017",1794016568,{"doc_id":163,"doc_title":164,"file_type":137,"home_preview_img_url":165,"slug":166,"view_count":33,"category_name":29,"create_tm":167},685683,"JSON - Quick Guide - Overview - Syntax - Datatypes","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229999686685/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796110559&Signature=CHmW0NY6bVXh1t%2F6O2Ci8vIzGiM%3D","json-quick-guide-overview-syntax-datatypes",1794016574,{"doc_id":169,"doc_title":170,"file_type":137,"home_preview_img_url":171,"slug":172,"view_count":22,"category_name":29,"create_tm":173},759560,"Introduction to YAML configuration - Network Startup Resource Center","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230044200992/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796110559&Signature=y4b%2BM78uS9y3D%2BCEB23E%2B9x%2FMhQ%3D","introduction-to-yaml-configuration-network-startup-resource-center",1795887859,{"doc_id":175,"doc_title":176,"file_type":137,"home_preview_img_url":177,"slug":178,"view_count":101,"category_name":29,"create_tm":179},682223,"Python PEP8 style guide - Cheat Sheet - Naming conventions - Maximum Line Length and Line Breaking - Indentation - Comments - Code Layout","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229999427735/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796110559&Signature=tdOXUWA4I35CkdjVK18Tm5Nb3rs%3D","python-pep8-style-guide-cheat-sheet-naming-conventions-maximum-line-length-and-line-breaking-indentation-comments-code-layout",1793963021,{"doc_id":181,"doc_title":182,"file_type":137,"home_preview_img_url":183,"slug":184,"view_count":185,"category_name":29,"create_tm":186},348233,"Markdown Cheat Sheet","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229911078256/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796110559&Signature=3DK8uZFZcZFoayp7%2FpFzqYKRBBU%3D","markdown-cheat-sheet",13,1790071894,{"doc_id":188,"doc_title":189,"file_type":137,"home_preview_img_url":190,"slug":191,"view_count":192,"category_name":29,"create_tm":193},501611,"Sams Teach Yourself - C++ in One Hour a Day - 6th ed.","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229931378859/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796110559&Signature=CEyRRDGfDjEUHiR3wPL%2FW09DHlI%3D","sams-teach-yourself-c-in-one-hour-a-day-6th-ed",17,1791021464,{"doc_id":195,"doc_title":196,"file_type":137,"home_preview_img_url":197,"slug":198,"view_count":96,"category_name":29,"create_tm":199},628750,"Desmos 2nd File - Graphing Calculator Shortcuts & Function List","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229967613495/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796110559&Signature=eoPaIW4CtIiEVXlNMVsjNdb5d0k%3D","desmos-2nd-file-graphing-calculator-shortcuts-function-list",1792618451,{"doc_id":201,"doc_title":202,"file_type":137,"home_preview_img_url":203,"slug":204,"view_count":30,"category_name":29,"create_tm":205},685787,"Arrays - Java Arrays vs Python Lists - Learn how to declare and use arrays in Java","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000208980/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796110559&Signature=2vg1yeh5AfoIULp8MFHDH6D3yFE%3D","arrays-java-arrays-vs-python-lists-learn-how-to-declare-and-use-arrays-in-java",1794018478,{"doc_id":207,"doc_title":208,"file_type":137,"home_preview_img_url":209,"slug":210,"view_count":105,"category_name":29,"create_tm":211},700982,"Java Scripting Programmer's Guide - Release 11","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230011575643/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796110559&Signature=OTKT9L5brY%2FFeVU8Djn1LIQ0z%2F8%3D","java-scripting-programmers-guide-release-11",1794522624,{"doc_id":213,"doc_title":214,"file_type":137,"home_preview_img_url":215,"slug":216,"view_count":96,"category_name":29,"create_tm":217},685805,"Numpy - Array - Chapter 11 - Informatics Practices","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000213217/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796110559&Signature=iXUZOxlaLWQSF5eawVO6ojnxqHM%3D","numpy-array-chapter-11-informatics-practices",1794018711]