{"id":956,"date":"2018-02-16T10:24:08","date_gmt":"2018-02-16T10:24:08","guid":{"rendered":"http:\/\/learnlearn.uk\/python\/?page_id=956"},"modified":"2024-10-01T10:16:53","modified_gmt":"2024-10-01T10:16:53","slug":"lesson-6-lists","status":"publish","type":"page","link":"https:\/\/learnlearn.uk\/python\/lesson-6-lists\/","title":{"rendered":"Topic 6 &#8211; Lists (1 dimensional arrays)"},"content":{"rendered":"<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">Tutorial Video<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Mini Tutorial Videos<\/h3>\n<p><a href=\"https:\/\/youtu.be\/V0tSGodNTYw\">Video 1 &#8211; How to Create Lists<\/a><\/p>\n<p><a href=\"https:\/\/youtu.be\/Ys-oxElF1h8\">Video 2 &#8211; How to add \/ append items to a list<\/a><\/p>\n<p><a href=\"https:\/\/youtu.be\/l-nZ9wjREoA\">Video 3 &#8211; How to remove \/ pop items from a list<\/a><\/p>\n<p><a href=\"https:\/\/youtu.be\/N4qcaYNNrTA\">Video 4- How to loop through a Python list<\/a><\/p>\n<p><a href=\"https:\/\/youtu.be\/5mjggVFDc3w\">Video 5 &#8211; How to use if statements with lists<\/a><\/p>\n<p><a href=\"https:\/\/youtu.be\/fjxxeG6HjnU\">Video 6 &#8211; Finding items in a list<\/a><\/p>\n<p><a href=\"https:\/\/youtu.be\/l6uZodZVzAY\">Video 7 &#8211; How to sort a list in Python<\/a><\/p>\n<p><a href=\"https:\/\/youtu.be\/utvV79QKyrc\">Video 8 &#8211; How to shuffle \/ randomise a list<\/a><\/p>\n<p><a href=\"https:\/\/youtu.be\/aouZGuuYr3k\">Video 9 &#8211; How to convert a list to a string (and back again)<\/a><\/p>\n<p>Full playlist video on YouTube<\/p>\n<p><iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/videoseries?list=PLfd-8l91Lb4VclnjJMvc3f4qVvmOp0bZb\" width=\"853\" height=\"480\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p><a href=\"https:\/\/drive.google.com\/file\/d\/0B4M7J3ubGpimbjhaa1V2RUhLRzA\/view?usp=sharing\">Can&#8217;t access YouTube? Click here for the Google Drive version<\/a><\/p>\n\n<\/div><h2 class=\"tabtitle\">Cheat Sheet<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Python Lists Cheat Sheet<\/h3>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\">#Create an empty list<\/span>\r\n\r\nl <span style=\"color: #333333;\">=<\/span> [] \r\n\r\n<span style=\"color: #888888;\">#Create a list with items in it<\/span>\r\nl <span style=\"color: #333333;\">=<\/span> [<span style=\"background-color: #fff0f0;\">\"dog\"<\/span>,<span style=\"background-color: #fff0f0;\">\"cat\"<\/span>,<span style=\"background-color: #fff0f0;\">\"mouse\"<\/span>]\r\n\r\n<span style=\"color: #888888;\">#get the user to add items to a list<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">for<\/span> i <span style=\"color: #000000; font-weight: bold;\">in<\/span> <span style=\"color: #007020;\">range<\/span>(<span style=\"color: #0000dd; font-weight: bold;\">5<\/span>):\r\n    l<span style=\"color: #333333;\">.<\/span>append(<span style=\"color: #007020;\">input<\/span>(<span style=\"background-color: #fff0f0;\">\"What to add?\"<\/span>))\r\n\r\n<span style=\"color: #888888;\">#print all items in a list<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">for<\/span> item <span style=\"color: #000000; font-weight: bold;\">in<\/span> l:\r\n    <span style=\"color: #008800; font-weight: bold;\">print<\/span>(<span style=\"background-color: #fff0f0;\">\"Your item is  -\"<\/span>, item)\r\n\r\n<span style=\"color: #888888;\">#remove the last item from a list:<\/span>\r\nl<span style=\"color: #333333;\">.<\/span>pop()\r\n\r\n<span style=\"color: #888888;\">#remove the first item from list<\/span>\r\nl<span style=\"color: #333333;\">.<\/span>pop(<span style=\"color: #0000dd; font-weight: bold;\">0<\/span>)\r\n\r\n<span style=\"color: #888888;\">#remove a item and save it to a variable<\/span>\r\nchosen <span style=\"color: #333333;\">=<\/span> l<span style=\"color: #333333;\">.<\/span>pop()\r\n\r\n<span style=\"color: #888888;\">#reverse a lit<\/span>\r\nl<span style=\"color: #333333;\">.<\/span>reverse()\r\n\r\n<span style=\"color: #888888;\">#sort a list<\/span>\r\nl<span style=\"color: #333333;\">.<\/span>sort()\r\n\r\n<span style=\"color: #888888;\">#see if an item is in a list<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">if<\/span> <span style=\"background-color: #fff0f0;\">\"dog\"<\/span> <span style=\"color: #000000; font-weight: bold;\">in<\/span> l:\r\n    <span style=\"color: #008800; font-weight: bold;\">print<\/span>(<span style=\"background-color: #fff0f0;\">\"found!\"<\/span>)\r\n\r\n<span style=\"color: #888888;\"># Find the index of an item<\/span>\r\nl<span style=\"color: #333333;\">.<\/span>index(<span style=\"background-color: #fff0f0;\">\"dog\"<\/span>)\r\n\r\n<span style=\"color: #888888;\"># replace an item at a specific index in a list<\/span>\r\nl[<span style=\"color: #0000dd; font-weight: bold;\">3<\/span>] <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"cat\"<\/span>\r\n<\/pre>\n<\/div>\n\n<\/div><h2 class=\"tabtitle\">Challenge 21<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Challenge 21 &#8211; Favourite Movies<\/h3>\n<p>The user should be asked to enter the names of their 5 favourite movies.<\/p>\n<p><strong>Bronze<\/strong><\/p>\n<ul>\n<li>Your program should ask the user to enter 5\u00a0 movie titles into a list<\/li>\n<li>Once the user has entered all 5 names, the list contents should outputted back to the user<\/li>\n<\/ul>\n<p><strong>Silver<\/strong><\/p>\n<ul>\n<li>Your program should sort the list into Alphabetical order<\/li>\n<\/ul>\n<p><strong>Gold<\/strong><\/p>\n<ul>\n<li>Your program should ensure that the user&#8217;s input is valid, for each movie title entered<\/li>\n<\/ul>\n\n<\/div><h2 class=\"tabtitle\">22<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Challenge 22 &#8211; Race Recorder<\/h3>\n<p>Write a program that allows the user to enter the names of each person that finishes a running race. The program should then print out the full list of runners in the race, together with their position.<\/p>\n<p><strong>Bronze<\/strong><\/p>\n<ul>\n<li>The program should ask the user to enter 5 names<\/li>\n<li>The program should then print out a list of names, with each runner&#8217;s position next to them.<\/li>\n<\/ul>\n<p><strong>Silver<\/strong><\/p>\n<ul>\n<li>The program should be adapted to allow the user to keep entering as many names as they like. The program should stop asking for more names when the user presses enter with an empty name.<\/li>\n<li>The program should include the option to find a runner&#8217;s position in the race, if you enter their name.<\/li>\n<\/ul>\n<p><strong>Gold<\/strong><\/p>\n<ul>\n<li>The program should include menu functions with options for separate screens.<\/li>\n<\/ul>\n\n<\/div><h2 class=\"tabtitle\">23<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Challenge 23 &#8211; Shop Takings<\/h3>\n<p>Write a program that asks the user to enter the daily takings for a shop, for a week.<\/p>\n<p><strong>Bronze<\/strong><\/p>\n<ul>\n<li>The program should ask the user to enter 7 values<\/li>\n<li>The program should store each of the values in a list<\/li>\n<li>The program should print out the list at the end of the week<\/li>\n<li>The program should print out the total takings for the week.<\/li>\n<\/ul>\n<p><strong>Silver<\/strong><\/p>\n<ul>\n<li>The program should display the minimum, maximum and average daily takings for the week.<\/li>\n<li>The program should format the data in a suitable manner (make it look pretty)<\/li>\n<\/ul>\n<p><strong>Gold<\/strong><\/p>\n<ul>\n<li>The program should check the values entered each time to ensure that the are integers and repeat the question until a valid response is entered.<\/li>\n<\/ul>\n\n<\/div><h2 class=\"tabtitle\">24<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Challenge 24 &#8211; Card Picker<\/h3>\n<p><strong>Bronze<\/strong><\/p>\n<ul>\n<li>Create a program that generates a list of the 52 cards from a standard deck of cards, excluding the jokers.<\/li>\n<li>Your program should then pick a random card from the deck and output the chosen card to the user.<\/li>\n<\/ul>\n<p><strong>Silver<\/strong><\/p>\n<ul>\n<li>Your program should automatically create the list using loops, rather than the whole list of cards being manually typed out.<\/li>\n<\/ul>\n<p><strong>Gold<\/strong><\/p>\n<ul>\n<li>Each time a card is drawn, your program should remove that card from the list, so that it can&#8217;t be drawn again.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<\/div><\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Mini Tutorial Videos Video 1 &#8211; How to Create Lists Video 2 &#8211; How to add \/ append items to a list Video 3 &#8211; How to remove \/ pop items from a list Video 4- How to loop through a Python list Video 5 &#8211; How to use if statements with lists Video 6&hellip;&nbsp;<a href=\"https:\/\/learnlearn.uk\/python\/lesson-6-lists\/\" class=\"\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">Topic 6 &#8211; Lists (1 dimensional arrays)<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"off","neve_meta_content_width":70,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Topic 6 &#8211; Lists (1 dimensional arrays) - Python<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/learnlearn.uk\/python\/lesson-6-lists\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Topic 6 &#8211; Lists (1 dimensional arrays) - Python\" \/>\n<meta property=\"og:description\" content=\"Mini Tutorial Videos Video 1 &#8211; How to Create Lists Video 2 &#8211; How to add \/ append items to a list Video 3 &#8211; How to remove \/ pop items from a list Video 4- How to loop through a Python list Video 5 &#8211; How to use if statements with lists Video 6&hellip;&nbsp;Read More &raquo;Topic 6 &#8211; Lists (1 dimensional arrays)\" \/>\n<meta property=\"og:url\" content=\"https:\/\/learnlearn.uk\/python\/lesson-6-lists\/\" \/>\n<meta property=\"og:site_name\" content=\"Python\" \/>\n<meta property=\"article:modified_time\" content=\"2024-10-01T10:16:53+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/learnlearn.uk\/python\/lesson-6-lists\/\",\"url\":\"https:\/\/learnlearn.uk\/python\/lesson-6-lists\/\",\"name\":\"Topic 6 &#8211; Lists (1 dimensional arrays) - Python\",\"isPartOf\":{\"@id\":\"https:\/\/learnlearn.uk\/python\/#website\"},\"datePublished\":\"2018-02-16T10:24:08+00:00\",\"dateModified\":\"2024-10-01T10:16:53+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/learnlearn.uk\/python\/lesson-6-lists\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/learnlearn.uk\/python\/lesson-6-lists\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/learnlearn.uk\/python\/lesson-6-lists\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Python Unit Home\",\"item\":\"https:\/\/learnlearn.uk\/python\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Topic 6 &#8211; Lists (1 dimensional arrays)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/learnlearn.uk\/python\/#website\",\"url\":\"https:\/\/learnlearn.uk\/python\/\",\"name\":\"Python\",\"description\":\"Programming\",\"publisher\":{\"@id\":\"https:\/\/learnlearn.uk\/python\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/learnlearn.uk\/python\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/learnlearn.uk\/python\/#organization\",\"name\":\"Python\",\"url\":\"https:\/\/learnlearn.uk\/python\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/learnlearn.uk\/python\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2019\/03\/LearnLearnLogowhite.png\",\"contentUrl\":\"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2019\/03\/LearnLearnLogowhite.png\",\"width\":710,\"height\":98,\"caption\":\"Python\"},\"image\":{\"@id\":\"https:\/\/learnlearn.uk\/python\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Topic 6 &#8211; Lists (1 dimensional arrays) - Python","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/learnlearn.uk\/python\/lesson-6-lists\/","og_locale":"en_GB","og_type":"article","og_title":"Topic 6 &#8211; Lists (1 dimensional arrays) - Python","og_description":"Mini Tutorial Videos Video 1 &#8211; How to Create Lists Video 2 &#8211; How to add \/ append items to a list Video 3 &#8211; How to remove \/ pop items from a list Video 4- How to loop through a Python list Video 5 &#8211; How to use if statements with lists Video 6&hellip;&nbsp;Read More &raquo;Topic 6 &#8211; Lists (1 dimensional arrays)","og_url":"https:\/\/learnlearn.uk\/python\/lesson-6-lists\/","og_site_name":"Python","article_modified_time":"2024-10-01T10:16:53+00:00","twitter_card":"summary_large_image","twitter_misc":{"Estimated reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/learnlearn.uk\/python\/lesson-6-lists\/","url":"https:\/\/learnlearn.uk\/python\/lesson-6-lists\/","name":"Topic 6 &#8211; Lists (1 dimensional arrays) - Python","isPartOf":{"@id":"https:\/\/learnlearn.uk\/python\/#website"},"datePublished":"2018-02-16T10:24:08+00:00","dateModified":"2024-10-01T10:16:53+00:00","breadcrumb":{"@id":"https:\/\/learnlearn.uk\/python\/lesson-6-lists\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/learnlearn.uk\/python\/lesson-6-lists\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/learnlearn.uk\/python\/lesson-6-lists\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Python Unit Home","item":"https:\/\/learnlearn.uk\/python\/"},{"@type":"ListItem","position":2,"name":"Topic 6 &#8211; Lists (1 dimensional arrays)"}]},{"@type":"WebSite","@id":"https:\/\/learnlearn.uk\/python\/#website","url":"https:\/\/learnlearn.uk\/python\/","name":"Python","description":"Programming","publisher":{"@id":"https:\/\/learnlearn.uk\/python\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/learnlearn.uk\/python\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-GB"},{"@type":"Organization","@id":"https:\/\/learnlearn.uk\/python\/#organization","name":"Python","url":"https:\/\/learnlearn.uk\/python\/","logo":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/learnlearn.uk\/python\/#\/schema\/logo\/image\/","url":"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2019\/03\/LearnLearnLogowhite.png","contentUrl":"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2019\/03\/LearnLearnLogowhite.png","width":710,"height":98,"caption":"Python"},"image":{"@id":"https:\/\/learnlearn.uk\/python\/#\/schema\/logo\/image\/"}}]}},"rttpg_featured_image_url":null,"rttpg_author":{"display_name":"learnlearnadmin","author_link":"https:\/\/learnlearn.uk\/python\/author\/learnlearnadmin\/"},"rttpg_comment":0,"rttpg_category":null,"rttpg_excerpt":"Mini Tutorial Videos Video 1 &#8211; How to Create Lists Video 2 &#8211; How to add \/ append items to a list Video 3 &#8211; How to remove \/ pop items from a list Video 4- How to loop through a Python list Video 5 &#8211; How to use if statements with lists Video 6&hellip;&nbsp;Read&hellip;","_links":{"self":[{"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/pages\/956"}],"collection":[{"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/comments?post=956"}],"version-history":[{"count":21,"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/pages\/956\/revisions"}],"predecessor-version":[{"id":1486,"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/pages\/956\/revisions\/1486"}],"wp:attachment":[{"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/media?parent=956"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}