[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"detail-sidebar-cat-0-en-105":3,"doc-seo-685779-105":59,"doc-detail-685779-en":130,"doc-similar-685779":149},{"code":4,"msg":5,"data":6},0,"success",[7,13,18,23,28,33,38,43,48,51,55],{"id":8,"doc_module":4,"doc_module_name":9,"category_name":10,"show_sort_weight":11,"slug":12},1,"Document","Story & Novel",90,"story-novel",{"id":14,"doc_module":4,"doc_module_name":9,"category_name":15,"show_sort_weight":16,"slug":17},2,"Literature",80,"literature",{"id":19,"doc_module":4,"doc_module_name":9,"category_name":20,"show_sort_weight":21,"slug":22},4,"Exam",70,"exam",{"id":24,"doc_module":4,"doc_module_name":9,"category_name":25,"show_sort_weight":26,"slug":27},5,"Comic",60,"comic",{"id":29,"doc_module":4,"doc_module_name":9,"category_name":30,"show_sort_weight":31,"slug":32},6,"Technology",50,"technology",{"id":34,"doc_module":4,"doc_module_name":9,"category_name":35,"show_sort_weight":36,"slug":37},7,"Healthcare",40,"healthcare",{"id":39,"doc_module":4,"doc_module_name":9,"category_name":40,"show_sort_weight":41,"slug":42},8,"Research & Report",30,"research-report",{"id":44,"doc_module":4,"doc_module_name":9,"category_name":45,"show_sort_weight":46,"slug":47},9,"Religion & Spirituality",20,"religion-spirituality",{"id":46,"doc_module":4,"doc_module_name":9,"category_name":49,"show_sort_weight":46,"slug":50},"World Cup","world-cup",{"id":52,"doc_module":4,"doc_module_name":9,"category_name":53,"show_sort_weight":52,"slug":54},10,"Lifestyle","lifestyle",{"id":56,"doc_module":4,"doc_module_name":9,"category_name":57,"show_sort_weight":24,"slug":58},19,"General","general",{"code":4,"msg":60,"data":61},"ok",{"site_id":62,"language":63,"slug":64,"title":65,"keywords":66,"description":67,"schema_data":68,"social_meta":123,"head_meta":125,"extra_data":127,"updated_unix":129},105,"en","topic-6-lists-sets-tuples-dictionaries","Topic 6 - Lists, Sets, Tuples, Dictionaries","","Topic 6 class notes introduce core Python data structures—lists, sets, tuples, and dictionaries—focusing on what each structure is, how to iterate through items, and how to store and pass lists into functions. The material explains strings as character collections, demonstrates indexing and slicing, and contrasts mutable lists with immutable strings and tuples. Exercises build practical skills such as membership checks, overwriting list elements, using list operators, and creating a loop-driven friends list that sorts names alphabetically.",{"@graph":69,"@context":122},[70,84,105],{"@type":71,"itemListElement":72},"BreadcrumbList",[73,77,79,82],{"item":74,"name":75,"@type":76,"position":8},"https://docshare.wps.com","Home","ListItem",{"item":78,"name":9,"@type":76,"position":14},"https://docshare.wps.com/document/",{"item":80,"name":30,"@type":76,"position":81},"https://docshare.wps.com/document/technology/",3,{"item":83,"name":65,"@type":76,"position":19},"https://docshare.wps.com/document/topic-6-lists-sets-tuples-dictionaries/685779/",{"url":83,"name":65,"@type":85,"image":86,"author":91,"headline":65,"publisher":94,"fileFormat":97,"inLanguage":63,"description":67,"dateModified":98,"datePublished":99,"encodingFormat":97,"isAccessibleForFree":100,"interactionStatistic":101},"DigitalDocument",{"url":87,"@type":88,"width":89,"height":90},"https://docshare.wps.com/thumbnails/topic-6-lists-sets-tuples-dictionaries/685779.png","ImageObject",300,407,{"name":92,"@type":93},"วิน","Person",{"url":74,"name":95,"@type":96},"DocShare","Organization","application/pdf","2026-11-21","2026-11-07",true,{"@type":102,"interactionType":103,"userInteractionCount":24},"InteractionCounter",{"@type":104},"ViewAction",{"@type":106,"mainEntity":107},"FAQPage",[108,114,118],{"name":109,"@type":110,"acceptedAnswer":111},"How are strings treated in this topic, and how do indexing and slicing work?","Question",{"text":112,"@type":113},"A string is treated as a collection of characters. Characters can be accessed by index, including negative indexes, and substrings can be obtained using slicing with start/end positions.","Answer",{"name":115,"@type":110,"acceptedAnswer":116},"What is the key difference between mutable lists and immutable strings or tuples?",{"text":117,"@type":113},"Lists are mutable, so elements can be changed in memory. Strings and tuples are immutable, so attempts to modify individual characters or tuple items raise a TypeError.",{"name":119,"@type":110,"acceptedAnswer":120},"Which list operators are covered, and what does each do?",{"text":121,"@type":113},"The notes cover .append() to add an item to the end, .insert() to add at a specific position, .remove() to delete an item (raising ValueError if missing), and .copy() to duplicate a list. Continued operators include .count() to count occurrences, .reverse() to reverse in place, and .sort() to sort in place.","https://schema.org",{"og:url":83,"og:type":124,"og:title":65,"og:site_name":95,"og:description":67},"article",{"robots":126,"canonical":83},"index,follow",{"doc_id":128,"site_id":62},685779,1794018231,{"code":4,"msg":5,"data":131},{"doc_id":128,"user_id":132,"nickname":92,"user_avatar":133,"doc_module":4,"category_id":29,"category_name":30,"doc_title":65,"doc_description":67,"doc_content":134,"file_id":135,"file_url":136,"file_type":137,"file_size":138,"view_count":24,"is_deleted":4,"is_public":8,"is_downloadable":8,"audit_status":8,"page_count":44,"language":139,"language_code":63,"site_id":62,"html_lang":63,"table_of_contents":140,"faqs":141,"seo_title":142,"seo_description":67,"update_tm":129,"read_time":143,"preview_page_count":8,"preview_urls":144},2336475104736,"https://ap-avatar.wpscdn.com/avatar/22000c4c5e0e5b17e70?x-image-process=image/resize,m_fixed,w_180,h_180&k=1786591360781797222","Topic 6: Lists, Sets, Tuples, Dictionaries  \nGoals: By the end of this week, we will discuss…  \n- what are lists, sets, tuples, and dictionaries (data structures)  \n- how to iterate over the data structures  \n- storing and passing lists with functions  \nAcknowledgements: These class notes build on the content of my previous courses as well as the work of R. Jordan Crouser, and Jeffrey S. Castrucci.  \nRecall: Stings  \nOne way to think about a string is as a list/collection of characters:  \nname = \"Smith College\"  \n≈ ['S','m','i','t','h',' ','C','o','l','l','e','g','e'] 0 1 2 3 4 5 6 7 8 9 10 11 12  \n\n| >>> name = \"Smith College\"\u003Cbr>>>> name[2] \\# Index of a letter .\u003Cbr>'i'>>> name[-4]'l' |  |\n| --- | --- |\n| >>> name[:5]'Smith'>>> name[2:]'ith College'>>> name[1:5]'mith' | \\# Substring / slicing\u003Cbr>\\#up to but not including 5 |\n\n-Strings are collections of characters, deﬁned using \"quotes\".  \n-Lists are collections of objects, deﬁned using [ square brackets ].  \n-Just about anything can go in a list, for example....  \n>>> [1, 2, 3, 4, 5, 6] \\#list of integers  \n>>> [1 .2, 3 .5, 0 .7, 7 . 8] \\#list of floats  \n>>> [\"dog\", \"cat\", \"pig\"] \\#list of strings  \n-Lists can be indexed...just like strings  \n>>> animals = [\"dog\", \"cat\", \"pig\"]>>> animals[1]  \n\"cat\">>> animals[-2]\"cat\"  \n-Python allow for lists with mixed types, for example...  \n>>> [1, \"cat\", 7 . 8]  \nOther programming languages do not allow this, so use with extreme caution.  \nNaming convention  \n-Remember: it’s always a a good idea variable names to be descriptive  \n-Because lists contain collections of things, we’ll generally label them with a plural noun, for example....  \n-Just about anything can go in a list, for example....  \nnumbers = [1, 2, 3, 4, 5, 6]  \nnames = [\"Jordan\", \"Ray\", \"Maisie\"] prices = [1 .23, 3 .55, 0 .75, 7 . 80]  \nIterating through items in a list  \nnames = [\"Jordan\", \"Ray\", \"Maisie\"] for name in names:  \nprint(name)  \nChecking membership in a list  \nnames = [\"Jordan\", \"Ray\", \"Maisie\"]  \nnew_name = input(\"Enter a student's name: \")  \nif new_name in names:  \nprint(\"They are in the class . \") else:  \nprint(\"Hmm, I don't know them . \")  \nExercise: Friends  \n-Create a list of your friends and assign it to a new variable.  \n-Then depending on you user either print each name in ALL CAPS or lower case letters.  \n- If ALL CAPS, include an exclamation mark at the end (use a loop) .  \nOverwriting an item in a list  \n- If we want to overwrite an item in a list, we can use indexing combined with the = operator:  \n>>> animals = ['cat', 'dog', 'pig']>>> animals[2] = 'rabbit'>>> print(animals)  \n['cat', 'dog', 'rabbit']  \nQuestion: What happens when we try to do this with a string?  \nAnswer: A TypeError  \n>>> animal = 'bat'>>> animal[1] = 'd'  \nTraceback (most recent call last):  \nFile \"\u003Cpyshell\\#6>\", line 1, in \u003Cmodule>  \nanimal[1] = 'd'  \nTypeError: 'str' object does not support item assignment  \nMutable vs . Immutable  \n-strings are immutable (which means we cannot change them in memory, we have to overwrite them completely)  \n- lists deﬁned with […] are mutable (which means we can change them in memory)  \n- if we want an immutable lists, we can deﬁne them with (…) instead, for example:  \n>>> animals = ('cat', 'dog', 'pig') \\#immutable >>> animals[1]  \n'dog'  \n>>> animals[1] = 'bag'  \nTraceback (most recent call last):  \nFile \"\u003Cpyshell\\#9>\", line 1, in \u003Cmodule>  \nanimals[1] = 'bag'  \nTypeError: 'tuple' object does not support item assignment  \nList Operators  \n.append() - If you want to add a new item to the end of a list.  \n.insert() - If you want to add a new item into a list at a speciﬁc position.  \n.remove() - If you want to remove an item from a list, but if you try to remove an item that isn’t in the list, the interpreter will throw a ValueError.  \n.copy() - If you want to copy the list.  \nFor example:  \n>>> animals = ['cat', 'dog', 'pig', 'frog'] \\#mutable >>> animals .append('turtle')  \n>>> animals .insert(3, 'fish')  \n>>> animals .remove('cat')  \n>>>","cbCaio8z0k41yQu9","https://ap.wps.com/l/cbCaio8z0k41yQu9","pdf",116055,"English","# Topic 6: Lists, Sets, Tuples, Dictionaries\n## Goals and acknowledgements\n## Strings as character collections and slicing\n## Lists: indexing, mixed types, naming, and iteration\n## Membership tests and list overwriting\n## Mutable vs immutable (strings and tuples)\n## List operators: append, insert, remove, copy, count, reverse, sort\n## Exercises: Friends (Part 1 and Part 2)\n## Lists of lists","[{\"question\":\"How are strings treated in this topic, and how do indexing and slicing work?\",\"answer\":\"A string is treated as a collection of characters. Characters can be accessed by index, including negative indexes, and substrings can be obtained using slicing with start/end positions.\"},{\"question\":\"What is the key difference between mutable lists and immutable strings or tuples?\",\"answer\":\"Lists are mutable, so elements can be changed in memory. Strings and tuples are immutable, so attempts to modify individual characters or tuple items raise a TypeError.\"},{\"question\":\"Which list operators are covered, and what does each do?\",\"answer\":\"The notes cover .append() to add an item to the end, .insert() to add at a specific position, .remove() to delete an item (raising ValueError if missing), and .copy() to duplicate a list. Continued operators include .count() to count occurrences, .reverse() to reverse in place, and .sort() to sort in place.\"}]","Topic 6 - Lists, Sets, Tuples, Dictionaries | PDF",23,[145],{"page_no":8,"url":146,"width":147,"height":148},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/461c62a6bac3e4f44e59dbc4f23443b8.webp",983,1272,{"list":150,"token":66},[151,157,163,169,175,181,187,192,198,204],{"doc_id":152,"doc_title":153,"file_type":137,"home_preview_img_url":154,"slug":155,"view_count":34,"category_name":30,"create_tm":156},670917,"Python 3 Cheat Sheet - concise reference","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229988704071/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111039&Signature=o5VnWv8cGZE%2BxLB92u%2BSuKm%2BFnY%3D","python-3-cheat-sheet-concise-reference",1793572698,{"doc_id":158,"doc_title":159,"file_type":137,"home_preview_img_url":160,"slug":161,"view_count":81,"category_name":30,"create_tm":162},685772,"UNIT-IV - LIST, TUPLES, DICTIONARIES - Problem Solving and Python Programming","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000203776/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111039&Signature=CNGkKZLV7CFSy%2FVbYDFtsnrRfhY%3D","unit-iv-list-tuples-dictionaries-problem-solving-and-python-programming",1794018219,{"doc_id":164,"doc_title":165,"file_type":137,"home_preview_img_url":166,"slug":167,"view_count":34,"category_name":30,"create_tm":168},697976,"6.0001 Lecture 5 - Tuples, Lists, Aliasing, Mutability, Cloning","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230010146768/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111039&Signature=aBgJvoL%2BM3S3oiTq9Hy31Mq6N0A%3D","60001-lecture-5-tuples-lists-aliasing-mutability-cloning",1794446554,{"doc_id":170,"doc_title":171,"file_type":137,"home_preview_img_url":172,"slug":173,"view_count":29,"category_name":30,"create_tm":174},685629,"Chapter 2: Lists, Arrays and Dictionaries","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229999084017/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111039&Signature=EPbk31fWHGcFtXuQlgIm7Tk1c%2F4%3D","chapter-2-lists-arrays-and-dictionaries",1794016092,{"doc_id":176,"doc_title":177,"file_type":137,"home_preview_img_url":178,"slug":179,"view_count":81,"category_name":30,"create_tm":180},685777,"Lists and Tuples - Learn to create and use 1D lists, tuples and 2D lists","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000203949/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111039&Signature=DZ57kX%2Bg%2Fq8ZMoOXzAZJ85wIdeE%3D","lists-and-tuples-learn-to-create-and-use-1d-lists-tuples-and-2d-lists",1794018226,{"doc_id":182,"doc_title":183,"file_type":137,"home_preview_img_url":184,"slug":185,"view_count":29,"category_name":30,"create_tm":186},697978,"Lecture 4: Tuples, List Slicing, List Comprehension, Strings","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230010146771/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111039&Signature=1TYpNUqFirkv8qQwvifNBw3OdkA%3D","lecture-4-tuples-list-slicing-list-comprehension-strings",1794446559,{"doc_id":188,"doc_title":189,"file_type":137,"home_preview_img_url":190,"slug":191,"view_count":81,"category_name":30,"create_tm":168},697975,"Python Variable Types - Variable Assignment, Multiple Assignment, and Standard Data Types","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230010146715/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111039&Signature=4XuFN7d7fayM3I59XE4yLWb0vOc%3D","python-variable-types-variable-assignment-multiple-assignment-and-standard-data-types",{"doc_id":193,"doc_title":194,"file_type":137,"home_preview_img_url":195,"slug":196,"view_count":19,"category_name":30,"create_tm":197},685780,"Tuple in Python - Lecture 2","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000203975/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111039&Signature=tgH7l01Cipdhv1VLme%2FEFRYqLQQ%3D","tuple-in-python-lecture-2",1794018232,{"doc_id":199,"doc_title":200,"file_type":137,"home_preview_img_url":201,"slug":202,"view_count":34,"category_name":30,"create_tm":203},685771,"Compound Data - Lists, Tuples, Dictionaries - Unit IV - Learning Notes","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000203726/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111039&Signature=VklIF8uVmk9z4DpK3z9uf7Q42kQ%3D","compound-data-lists-tuples-dictionaries-unit-iv-learning-notes",1794018217,{"doc_id":205,"doc_title":206,"file_type":137,"home_preview_img_url":207,"slug":208,"view_count":19,"category_name":30,"create_tm":209},697980,"TUPLES AND DICTIONARIES - Introduction to Tuples","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230010146829/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111039&Signature=elc2L35%2BDddQD9m7aRF2edlgeHk%3D","tuples-and-dictionaries-introduction-to-tuples",1794446564]