{"cells":[{"cell_type":"markdown","id":"c30444b7-1163-4ad4-8366-c9e11499218d","metadata":{},"outputs":[],"source":["
\n"," \"cognitiveclass.ai\n","
\n"]},{"cell_type":"markdown","id":"22c8e9b2-4311-4a0e-b2a3-f02e1f05019e","metadata":{},"outputs":[],"source":["\n","# Lists in Python\n","\n","Estimated time needed: **30** minutes\n","\n","## Objectives\n","\n","After completing this lab you will be able to:\n","\n","* Perform list operations in Python, including indexing, list manipulation, and copy/clone list.\n"]},{"cell_type":"markdown","id":"bc78299f-6c90-4123-a910-7eee5e382c67","metadata":{},"outputs":[],"source":["

Table of Contents

\n","
\n"," \n","\n","
\n","\n","
\n"]},{"cell_type":"markdown","id":"3b5308ec-4d18-4b73-a858-b9bef5d0511f","metadata":{},"outputs":[],"source":["\n","## About the Dataset\n"]},{"cell_type":"markdown","id":"98728eeb-9322-46b4-9e31-c14a154d114e","metadata":{},"outputs":[],"source":["Imagine you received album recommendations from your friends and compiled all of the recommandations into a table, with specific information about each album.\n","\n","The table has one row for each movie and several columns:\n","\n","* **Artist** - Name of the artist\n","* **Album** - Name of the album\n","* **Released_year** - Year the album was released\n","* **Length_min_sec** - Length of the album (hours,minutes,seconds)\n","* **Genre** - Genre of the album\n","* **Music_recording_sales_millions** - Music recording sales (millions in USD) on [SONG://DATABASE](http://www.song-database.com/?utm_medium=Exinfluencer&utm_source=Exinfluencer&utm_content=000026UJ&utm_term=10006555&utm_id=NA-SkillsNetwork-Channel-SkillsNetworkCoursesIBMDeveloperSkillsNetworkPY0101ENSkillsNetwork19487395-2021-01-01)\n","* **Claimed_sales_millions** - Album's claimed sales (millions in USD) on [SONG://DATABASE](http://www.song-database.com/?utm_medium=Exinfluencer&utm_source=Exinfluencer&utm_content=000026UJ&utm_term=10006555&utm_id=NA-SkillsNetwork-Channel-SkillsNetworkCoursesIBMDeveloperSkillsNetworkPY0101ENSkillsNetwork19487395-2021-01-01)\n","* **Released** - Date on which the album was released\n","* **Soundtrack** - Indicates if the album is the movie soundtrack (Y) or (N)\n","* **Rating_of_friends** - Indicates the rating from your friends from 1 to 10\n","\n","
\n","
\n","\n","The Dataset can be seen below:\n","\n","\n","\n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n","
ArtistAlbumReleasedLengthGenreMusic recording sales (millions)Claimed sales (millions)ReleasedSoundtrackRating (friends)
Michael JacksonThriller198200:42:19Pop, rock, R&B466530-Nov-8210.0
AC/DCBack in Black198000:42:11Hard rock26.15025-Jul-808.5
Pink FloydThe Dark Side of the Moon197300:42:49Progressive rock24.24501-Mar-739.5
Whitney HoustonThe Bodyguard199200:57:44Soundtrack/R&B, soul, pop26.15025-Jul-80Y7.0
Meat LoafBat Out of Hell197700:46:33Hard rock, progressive rock20.64321-Oct-777.0
EaglesTheir Greatest Hits (1971-1975)197600:43:08Rock, soft rock, folk rock32.24217-Feb-769.5
Bee GeesSaturday Night Fever19771:15:54Disco20.64015-Nov-77Y9.0
Fleet wood Mac Rumours 197700:40:01Soft rock27.94004-Feb-779.5
\n"]},{"cell_type":"markdown","id":"5961509b-91d6-4482-beb3-286ae8c6ac91","metadata":{},"outputs":[],"source":["
\n"]},{"cell_type":"markdown","id":"aa112946-e442-400f-9356-3141801869c7","metadata":{},"outputs":[],"source":["\n","## Lists\n"]},{"cell_type":"markdown","id":"a68d315f-7df3-4190-ab85-816809824bc9","metadata":{},"outputs":[],"source":["\n","\n","## Indexing\n"]},{"cell_type":"markdown","id":"1f9a56d0-d6db-43d1-acad-34eea7175322","metadata":{},"outputs":[],"source":["We are going to take a look at lists in Python. A list is a sequenced collection of different objects such as integers, strings, and even other lists as well. The address of each element within a list is called an index. An index is used to access and refer to items within a list.\n"]},{"cell_type":"markdown","id":"39470258-f394-47e4-a450-a7cd5d4c3326","metadata":{},"outputs":[],"source":["\n"]},{"cell_type":"markdown","id":"0e8f7bdc-53a9-45c1-be2e-5281b2e5cbc3","metadata":{},"outputs":[],"source":["To create a list, type the list within square brackets \\[ ], with your content inside the parenthesis and separated by commas. Let us try it!\n"]},{"cell_type":"code","id":"4ee18120-736f-463f-871c-5000ebb80806","metadata":{},"outputs":[],"source":["# Create a list\n\nL = [\"Michael Jackson\", 10.1, 1982]\nL"]},{"cell_type":"markdown","id":"fa38fbe0-413d-4dbd-aa3d-4819a5545702","metadata":{},"outputs":[],"source":["We can use negative and regular indexing with a list:\n"]},{"cell_type":"markdown","id":"aba561be-16bf-432d-b429-07b93a9b1fb5","metadata":{},"outputs":[],"source":["\n"]},{"cell_type":"code","id":"ae486647-8057-4467-9f7d-4e0c675c7da6","metadata":{},"outputs":[],"source":["# Print the elements on each index\n\nprint('the same element using negative and positive indexing:\\n Postive:',L[0],\n'\\n Negative:' , L[-3] )\nprint('the same element using negative and positive indexing:\\n Postive:',L[1],\n'\\n Negative:' , L[-2] )\nprint('the same element using negative and positive indexing:\\n Postive:',L[2],\n'\\n Negative:' , L[-1] )"]},{"cell_type":"markdown","id":"4d66bf96-2792-45a9-9a48-0bb5b469f5c4","metadata":{},"outputs":[],"source":["\n","## List Content\n"]},{"cell_type":"markdown","id":"c7ee682c-c9e9-4b3c-bb63-6a903b615df2","metadata":{},"outputs":[],"source":["Lists can contain strings, floats, and integers. We can nest other lists, and we can also nest tuples and other data structures. The same indexing conventions apply for nesting:\n"]},{"cell_type":"code","id":"83cfd886-785e-46b9-bab2-386ab21b6144","metadata":{},"outputs":[],"source":["# Sample List\n\n[\"Michael Jackson\", 10.1, 1982, [1, 2], (\"A\", 1)]"]},{"cell_type":"markdown","id":"dcf25309-19e6-4223-9866-10fae489c5d2","metadata":{},"outputs":[],"source":["\n","## List Operations\n"]},{"cell_type":"markdown","id":"fadfa9ab-ae24-47b4-95db-262ec0444b53","metadata":{},"outputs":[],"source":["We can also perform slicing in lists. For example, if we want the last two elements, we use the following command:\n"]},{"cell_type":"code","id":"5ddcade7-9b42-43e5-9340-09693309bfa9","metadata":{},"outputs":[],"source":["# Sample List\n\nL = [\"Michael Jackson\", 10.1,1982,\"MJ\",1]\nL"]},{"cell_type":"markdown","id":"7c8a500f-d710-4f49-849f-5967a55899c2","metadata":{},"outputs":[],"source":["\n"]},{"cell_type":"code","id":"0abe9382-69b6-4f19-87bb-ded6f1382019","metadata":{},"outputs":[],"source":["# List slicing\n\nL[3:5]"]},{"cell_type":"markdown","id":"716a15d9-bd15-4216-acd1-b9d4eddf9e09","metadata":{},"outputs":[],"source":["We can use the method extend to add new elements to the list:\n"]},{"cell_type":"code","id":"52ab07d2-69d0-42cb-9ca8-8496c579a9cb","metadata":{},"outputs":[],"source":["# Use extend to add elements to list\n\nL = [ \"Michael Jackson\", 10.2]\nL.extend(['pop', 10])\nL"]},{"cell_type":"markdown","id":"a7ecd8c4-4b47-4995-8061-201b1fe30105","metadata":{},"outputs":[],"source":["Another similar method is append. If we apply append instead of extend, we add one element to the list:\n"]},{"cell_type":"code","id":"dcae0a42-37e1-430b-80b1-df553972d89d","metadata":{},"outputs":[],"source":["# Use append to add elements to list\n\nL = [ \"Michael Jackson\", 10.2]\nL.append(['pop', 10])\nL"]},{"cell_type":"markdown","id":"cc408db9-65b0-426d-b105-b942535b8e63","metadata":{},"outputs":[],"source":["Each time we apply a method, the list changes. If we apply extend we add two new elements to the list. The list L is then modified by adding two new elements:\n"]},{"cell_type":"code","id":"35696b79-c288-4752-b991-34d763d7beeb","metadata":{},"outputs":[],"source":["# Use extend to add elements to list\n\nL = [ \"Michael Jackson\", 10.2]\nL.extend(['pop', 10])\nL"]},{"cell_type":"markdown","id":"0e16a1d3-5e0c-4697-a7a3-4eed92481355","metadata":{},"outputs":[],"source":["If we append the list \\['a','b'] we have one new element consisting of a nested list:\n"]},{"cell_type":"code","id":"3f102f43-e80b-4c86-80de-33799cd99d5b","metadata":{},"outputs":[],"source":["# Use append to add elements to list\n\nL.append(['a','b'])\nL"]},{"cell_type":"markdown","id":"e061f0b3-365e-45ec-8a35-c7b0180cd23d","metadata":{},"outputs":[],"source":["As lists are mutable, we can change them. For example, we can change the first element as follows:\n"]},{"cell_type":"code","id":"863c20f1-c61a-4b54-94bc-5846bc7b3d21","metadata":{},"outputs":[],"source":["# Change the element based on the index\n\nA = [\"disco\", 10, 1.2]\nprint('Before change:', A)\nA[0] = 'hard rock'\nprint('After change:', A)"]},{"cell_type":"markdown","id":"b63e3d7d-d3ef-47a1-9766-30c18bbffa92","metadata":{},"outputs":[],"source":["We can also delete an element of a list using the del command:\n"]},{"cell_type":"code","id":"93f6df4f-9195-46c2-8c02-aa63ce7d694a","metadata":{},"outputs":[],"source":["# Delete the element based on the index\n\nprint('Before change:', A)\ndel(A[0])\nprint('After change:', A)"]},{"cell_type":"markdown","id":"1c2f2555-c9e4-44df-a32e-3ec57fd56d4b","metadata":{},"outputs":[],"source":["We can convert a string to a list using split. For example, the method split translates every group of characters separated by a space into an element in a list:\n"]},{"cell_type":"code","id":"501be38e-6f35-4de8-a01c-2ca1d1245219","metadata":{},"outputs":[],"source":["# Split the string, default is by space\n\n'hard rock'.split()"]},{"cell_type":"markdown","id":"6170fe6e-d4fd-4f17-bb3d-e066d09b0f1f","metadata":{},"outputs":[],"source":["We can use the split function to separate strings on a specific character which we call a **delimiter**. We pass the character we would like to split on into the argument, which in this case is a comma. The result is a list, and each element corresponds to a set of characters that have been separated by a comma:\n"]},{"cell_type":"code","id":"2c13e8cb-c308-44cc-a071-1a6634f1a02f","metadata":{},"outputs":[],"source":["# Split the string by comma\n\n'A,B,C,D'.split(',')"]},{"cell_type":"markdown","id":"bbb00c9f-ce1f-410e-a704-369940d49517","metadata":{},"outputs":[],"source":["\n","## Copy and Clone List\n"]},{"cell_type":"markdown","id":"c707ec5e-46a7-4dab-a6ed-8742f8af1b01","metadata":{},"outputs":[],"source":["When we set one variable B equal to A, both A and B are referencing the same list in memory:\n"]},{"cell_type":"code","id":"a54df6a9-55ae-4a26-a6df-ac72a8702fcd","metadata":{},"outputs":[],"source":["# Copy (copy by reference) the list A\n\nA = [\"hard rock\", 10, 1.2]\nB = A\nprint('A:', A)\nprint('B:', B)"]},{"cell_type":"markdown","id":"632fd574-c12e-4c8d-88de-b1eebbfe0a2d","metadata":{},"outputs":[],"source":["\n"]},{"cell_type":"markdown","id":"997adac1-dee1-4130-ab5c-0ac93306cd3f","metadata":{},"outputs":[],"source":["Initially, the value of the first element in B is set as \"hard rock\". If we change the first element in A to \"banana\", we get an unexpected side effect. As A and B are referencing the same list, if we change list A, then list B also changes. If we check the first element of B we get \"banana\" instead of \"hard rock\":\n"]},{"cell_type":"code","id":"4a2aed50-a02a-41cd-b5af-1c24fcbbcee1","metadata":{},"outputs":[],"source":["# Examine the copy by reference\n\nprint('B[0]:', B[0])\nA[0] = \"banana\"\nprint('B[0]:', B[0])"]},{"cell_type":"markdown","id":"66971c13-d97f-4460-beef-8cf1da1d9bfb","metadata":{},"outputs":[],"source":["This is demonstrated in the following figure:\n"]},{"cell_type":"markdown","id":"5c995ef6-a3e2-4b36-a01d-8dc37a233ebc","metadata":{},"outputs":[],"source":["\n"]},{"cell_type":"markdown","id":"d888ce6d-f4b0-4e5f-ae9e-b8fd67207b85","metadata":{},"outputs":[],"source":["You can clone list **A** by using the following syntax:\n"]},{"cell_type":"code","id":"99f769c3-7029-47b0-a911-2a9cedf70646","metadata":{},"outputs":[],"source":["# Clone (clone by value) the list A\n\nB = A[:]\nB"]},{"cell_type":"markdown","id":"9d27a3f9-813c-4521-8126-5f185dd8ec75","metadata":{},"outputs":[],"source":["Variable **B** references a new copy or clone of the original list. This is demonstrated in the following figure:\n"]},{"cell_type":"markdown","id":"2ac1ffbc-eec9-43cc-b8e5-95a514d16b0c","metadata":{},"outputs":[],"source":["\n"]},{"cell_type":"markdown","id":"68acd7c1-45d6-484c-8068-567b4e03cb89","metadata":{},"outputs":[],"source":["Now if you change A, B will not change:\n"]},{"cell_type":"code","id":"a0b11df4-bf57-4d3d-85d7-4515557f5dd5","metadata":{},"outputs":[],"source":["print('B[0]:', B[0])\nA[0] = \"hard rock\"\nprint('B[0]:', B[0])"]},{"cell_type":"markdown","id":"5de43784-bda1-4c3b-b52c-ad06fc623026","metadata":{},"outputs":[],"source":["\n","## Quiz on List\n"]},{"cell_type":"markdown","id":"a9635d20-3106-4125-af6b-b80f00b88f9e","metadata":{},"outputs":[],"source":["Create a list a_list, with the following elements 1, hello, \\[1,2,3] and True.\n"]},{"cell_type":"code","id":"b1ab480b-f2ae-420c-9518-9b5da41624bd","metadata":{},"outputs":[],"source":["# Write your code below and press Shift+Enter to execute\n"]},{"cell_type":"markdown","id":"495fb969-3f3a-4cb3-9c3b-021f7d1f91a3","metadata":{},"outputs":[],"source":["
Click here for the solution\n","\n","```python\n","a_list = [1, 'hello', [1, 2, 3] , True]\n","a_list\n","\n","```\n","\n","
\n"]},{"cell_type":"markdown","id":"02bef46b-02ea-4115-95b4-bcb3dcefbf90","metadata":{},"outputs":[],"source":["Find the value stored at index 1 of a_list.\n"]},{"cell_type":"code","id":"72232d4d-5ee5-4c88-bcd5-bbd5597c1aa4","metadata":{},"outputs":[],"source":["# Write your code below and press Shift+Enter to execute\n"]},{"cell_type":"markdown","id":"792488fb-6f11-412e-8206-accdd2a1030e","metadata":{},"outputs":[],"source":["
Click here for the solution\n","\n","```python\n","a_list[1]\n","\n","```\n","\n","
\n"]},{"cell_type":"markdown","id":"f79a5aa3-5984-4b6a-b521-05ccdc7a8d03","metadata":{},"outputs":[],"source":["Retrieve the elements stored at index 1, 2 and 3 of a_list.\n"]},{"cell_type":"code","id":"3cbcf013-7f7f-4a61-9c76-4db9a3d9d556","metadata":{},"outputs":[],"source":["# Write your code below and press Shift+Enter to execute\n"]},{"cell_type":"markdown","id":"16668448-36f7-462a-8b98-9c9af5a570f5","metadata":{},"outputs":[],"source":["
Click here for the solution\n","\n","```python\n","a_list[1:4]\n","\n","```\n","\n","
\n"]},{"cell_type":"markdown","id":"ac4cc616-9135-467b-98f7-5e3b05eb0604","metadata":{},"outputs":[],"source":["Concatenate the following lists A = \\[1, 'a'] and B = \\[2, 1, 'd']:\n"]},{"cell_type":"code","id":"65dd86af-ac15-418b-b789-e347e8a6a01a","metadata":{},"outputs":[],"source":["# Write your code below and press Shift+Enter to execute\n"]},{"cell_type":"markdown","id":"f292e7a0-0b05-4c6a-93c1-e12900bbcd54","metadata":{},"outputs":[],"source":["
Click here for the solution\n","\n","```python\n","A = [1, 'a'] \n","B = [2, 1, 'd']\n","A + B\n","\n","```\n","\n","
\n"]},{"cell_type":"markdown","id":"731882d6-18a2-4ca2-99d5-cba11cd4432a","metadata":{},"outputs":[],"source":["\n","## Scenario : Shopping list \n"]},{"cell_type":"markdown","id":"e1c4cdb7-5e43-4a8f-a8e6-3e0eba61598e","metadata":{},"outputs":[],"source":["# Task-1 Create an empty list\n","At first we need to create a empty list for storing the items to buy in Shopping list.\n"]},{"cell_type":"code","id":"428bb94f-2664-4fae-8534-8634b59b3141","metadata":{},"outputs":[],"source":["#Type your code here"]},{"cell_type":"markdown","id":"f1c8cda8-8fa7-4e10-b7c5-2eeb63b0aeef","metadata":{},"outputs":[],"source":["
Click here for the solution\n","\n","```python\n","Shopping_list=[]\n","\n","```\n","\n","
\n"]},{"cell_type":"markdown","id":"e445e1ed-fcb1-46d5-b1d4-79ccb6112bb4","metadata":{},"outputs":[],"source":["# Task-2 Now store the number of items to the shopping_list\n","* Watch\n","* Laptop\n","* Shoes\n","* Pen\n","* Clothes\n","\n","\n","
\n","\n"]},{"cell_type":"code","id":"a7a6f3e4-40cb-4bec-9b87-283d1a0fb808","metadata":{},"outputs":[],"source":["#Type your code here"]},{"cell_type":"markdown","id":"9ca25e18-fbcf-4cce-a7cd-b0be065c8f38","metadata":{},"outputs":[],"source":["
Click here for the hint \n","\n","```python\n","Hint:- Directly store every item as a different string in the list.\n","\n","```\n","\n","
\n"]},{"cell_type":"markdown","id":"a676739c-2134-4fda-ba41-7b8c711b9e16","metadata":{},"outputs":[],"source":["
Click here for the solution\n","\n","```python\n","Shopping_list=[\"Watch\",\"Laptop\",\"Shoes\",\"Pen\",\"Clothes\"]\n","\n","```\n","\n","
\n"]},{"cell_type":"markdown","id":"d8ed9f7a-cb86-4262-a293-cf6c6a55a137","metadata":{},"outputs":[],"source":["# Task-3 Add a new item to the shopping_list\n","Seems like I missed one item \"Football\" to add in the shopping list.\n","
\n"]},{"cell_type":"code","id":"8e01a534-8a98-4e12-820f-30937c26196c","metadata":{},"outputs":[],"source":["#Type your code here"]},{"cell_type":"markdown","id":"1918d425-42e3-4802-965a-da5bc17944dd","metadata":{},"outputs":[],"source":["
Click here for the hint \n","\n","```python\n","Hint:- Use `Append()` method for adding \"Football\" to our shopping list\n","\n","```\n","\n","
\n"]},{"cell_type":"markdown","id":"e750a937-a606-4f9e-98d5-a6738575130b","metadata":{},"outputs":[],"source":["
Click here for the solution\n","\n","```python\n","Shopping_list.append(\"Football\")\n","\n","```\n","\n","
\n"]},{"cell_type":"markdown","id":"35147a74-3696-40e2-b2ea-75c82c7d96b4","metadata":{},"outputs":[],"source":["# Task-4 Print First item from the shopping_list\n","Let's check the first item that we need to buy.\n","
\n"]},{"cell_type":"code","id":"739289ce-3787-4405-895d-834ffd07c4d0","metadata":{},"outputs":[],"source":["#Type your code here"]},{"cell_type":"markdown","id":"434e5ee8-bdd0-4f03-a1fe-97e08f55f8d4","metadata":{},"outputs":[],"source":["
Click here for the hint \n","\n","```python\n","Hint:- Use `indexing` for checking the first item.\n","\n","```\n","\n","
\n"]},{"cell_type":"markdown","id":"5a1d4a75-2053-4302-8528-e4da7ae5718e","metadata":{},"outputs":[],"source":["
Click here for the solution\n","\n","```python\n","print(Shopping_list[0])\n","\n","```\n","\n","
\n"]},{"cell_type":"markdown","id":"2ea82b17-b66a-4305-b675-7a95cd54a000","metadata":{},"outputs":[],"source":["# Task-5 Print Last item from the shopping_list\n","Let's check the last time that we need to buy.\n","
\n"]},{"cell_type":"code","id":"bdeb5c86-dab9-41da-917d-19d3ee97cdeb","metadata":{},"outputs":[],"source":["#Type your code here"]},{"cell_type":"markdown","id":"2bf15c72-18fd-4693-ae10-f5109657f58c","metadata":{},"outputs":[],"source":["
Click here for the hint \n","\n","```python\n","Hint:- Use `indexing` for checking for last item.\n","\n","```\n","\n","
\n"]},{"cell_type":"markdown","id":"71467a6d-7e9b-4aa8-ac16-9cbef27b727a","metadata":{},"outputs":[],"source":["
Click here for the solution\n","\n","```python\n","print(Shopping_list[-1])\n","\n","```\n","\n","
\n"]},{"cell_type":"markdown","id":"74fe5589-0b49-4522-a012-39672c50f7ba","metadata":{},"outputs":[],"source":["# Task-6 Print the entire Shopping List\n"]},{"cell_type":"code","id":"2cfd1c64-fbfc-40b0-a898-c98ca7e86622","metadata":{},"outputs":[],"source":["#Type your code here."]},{"cell_type":"markdown","id":"cccd0b57-1dfe-49ef-aec9-a1b37389a5af","metadata":{},"outputs":[],"source":["
Click here for the solution\n","\n","```python\n","print(Shopping_list)\n","\n","```\n","\n","
\n"]},{"cell_type":"markdown","id":"5dd991f0-aad8-43ac-9fdf-00714ad46cec","metadata":{},"outputs":[],"source":["# Task-7 Print the item that are important to buy from the Shopping List\n","Print \"Laptop\" and \"shoes\"\n"]},{"cell_type":"code","id":"22ec1e23-7d52-4b39-a3ed-cc05e988a079","metadata":{},"outputs":[],"source":["#Type your code here"]},{"cell_type":"markdown","id":"6a720bd0-9c24-4d0b-adb5-bb4fcf916b7f","metadata":{},"outputs":[],"source":["
Click here for the hint \n","\n","```python\n","Hint:- Use `slicing` to print \"Laptop\" and \"Shoes\"\n","\n","```\n","\n","
\n"]},{"cell_type":"markdown","id":"1185861f-10e5-4c7e-951e-fe54a6d0302c","metadata":{},"outputs":[],"source":["
Click here for the solution\n","\n","```python\n","print(Shopping_list[1:3])\n","\n","```\n","\n","
\n"]},{"cell_type":"markdown","id":"65b0c4c0-ec24-44c2-845e-3ea87c786922","metadata":{},"outputs":[],"source":["# Task-8 Change the item from the shopping_list \n","Instead of \"Pen\" I want to buy \"Notebook\"\n","let's change the item stored in the list.\n","
\n","\n"]},{"cell_type":"code","id":"884eb5a9-d1a7-46ed-b441-48c5bb099a1e","metadata":{},"outputs":[],"source":["#Type your code here"]},{"cell_type":"markdown","id":"b5934ab1-84bd-43ac-bc05-58ff3aa70805","metadata":{},"outputs":[],"source":["
Click here for the hint \n","\n","```python\n","Hint:- Locate the item you want to change using `index`, and Update the item with the new desired value using `string`.\n","\n","```\n","\n","
\n"]},{"cell_type":"markdown","id":"f0b8d18e-960b-4e80-a120-ff7ca018b49c","metadata":{},"outputs":[],"source":["
Click here for the solution\n","\n","```python\n","Shopping_list[3] = \"Notebook\"\n","\n","```\n","\n","
\n"]},{"cell_type":"markdown","id":"9650a550-6ea6-47cb-8d50-2a674ecf7641","metadata":{},"outputs":[],"source":["# Task-9 Delete the item from the shopping_list that is not required\n","Let's delete items that are unimportant, such as; I don't want to buy Clothes, let's delete it.\n","
\n","\n"]},{"cell_type":"code","id":"9e14ab03-9cd0-418f-84f1-d9aa118ae971","metadata":{},"outputs":[],"source":["#Type your code here"]},{"cell_type":"markdown","id":"7cd40a40-9cb9-423d-a896-95483a6b7fe6","metadata":{},"outputs":[],"source":["
Click here for the hint \n","\n","```python\n","Hint:- Use `del` method for deleting.\n","\n","```\n","\n","
\n"]},{"cell_type":"markdown","id":"bc7c448e-182a-4904-a562-25f3c261d988","metadata":{},"outputs":[],"source":["
Click here for the solution\n","\n","```python\n","del (Shopping_list[4])\n","\n","```\n","\n","
\n"]},{"cell_type":"markdown","id":"d4ddb024-6943-42f7-b41e-3188d7f88c66","metadata":{},"outputs":[],"source":["# Task-10 Print the shopping list\n","We are ready with our shopping list.\n"]},{"cell_type":"code","id":"127b56c7-7d5a-4337-8b86-dcde2bd32a79","metadata":{},"outputs":[],"source":["# Type your code here"]},{"cell_type":"markdown","id":"f3424948-38a6-419b-8036-51fa1e5abb28","metadata":{},"outputs":[],"source":["
Click here for the solution\n","\n","```python\n","print(Shopping_list)\n","\n","```\n","\n","
\n"]},{"cell_type":"markdown","id":"44be67cc-72d1-4314-91e2-819d9a056cb2","metadata":{},"outputs":[],"source":["
\n","

The last exercise!

\n","

Congratulations, you have completed your first lesson and hands-on lab in Python. \n","


\n"]},{"cell_type":"code","id":"702b9758-5a36-4230-87cc-4bdce51ff611","metadata":{},"outputs":[],"source":["## Author\n\nJoseph Santarcangelo\n\n## Other contributors\n\nMavis Zhou\n\n\n\n\n\n\n\n\n\n\n\n\n"]},{"cell_type":"code","id":"d0828658-4ead-46c4-ab87-2f03bf2dc82b","metadata":{},"outputs":[],"source":[""]}],"metadata":{"kernelspec":{"name":"python","display_name":"Python (Pyodide)","language":"python"},"language_info":{"codemirror_mode":{"name":"python","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.8"},"prev_pub_hash":"41ff67a140ed112dc69e273c9c35370479fdc0599ac7203f845808e59876b539"},"nbformat":4,"nbformat_minor":4}