title
How to Use Lists in Python

description
How to use lists in Python. Learn Python basics with this Python tutorial for beginners. 🔥Subscribe for more Python tutorials like this: https://goo.gl/SjXTT7 🔥Python tutorial for beginners: https://youtu.be/yE9v9rt6ziw Python Exercises for Beginners: https://programmingwithmosh.com/python/python-exercises-and-questions-for-beginners/ Python Cheat Sheet: https://programmingwithmosh.com/python/python-3-cheat-sheet/ Want to learn more from me? Check out my blog and courses: http://programmingwithmosh.com https://www.facebook.com/programmingwithmosh/ https://twitter.com/moshhamedani

detail
{'title': 'How to Use Lists in Python', 'heatmap': [{'end': 383.062, 'start': 354.766, 'weight': 0.728}, {'end': 610.476, 'start': 595.689, 'weight': 0.757}, {'end': 670.235, 'start': 652.429, 'weight': 0.824}, {'end': 756.754, 'start': 676.197, 'weight': 0.858}, {'end': 824.596, 'start': 798.56, 'weight': 0.735}, {'end': 941.414, 'start': 888.333, 'weight': 0.808}, {'end': 1023.895, 'start': 1003.63, 'weight': 0.983}, {'end': 1110.56, 'start': 1082.631, 'weight': 0.93}], 'summary': "Tutorial 'how to use lists in python' provides a comprehensive overview of python data structures, list manipulation, unpacking, looping, and essential list methods, covering topics such as creating two-dimensional lists, concatenating lists, list unpacking, packing, and looping, with practical examples and quantifiable techniques.", 'chapters': [{'end': 368.11, 'segs': [{'end': 116.969, 'src': 'embed', 'start': 4.372, 'weight': 0, 'content': [{'end': 11.174, 'text': "In this section, we're going to look at the built-in data structures in Python, which are extremely important when building real applications.", 'start': 4.372, 'duration': 6.802}, {'end': 16.435, 'text': "First, we're going to look at lists, and then we'll look at tuples, sets, and dictionaries.", 'start': 11.814, 'duration': 4.621}, {'end': 23.277, 'text': 'So earlier you have seen that we can use square brackets to define a list or a sequence of objects.', 'start': 17.156, 'duration': 6.121}, {'end': 26.798, 'text': 'In between these brackets, we can have objects of any type.', 'start': 23.977, 'duration': 2.821}, {'end': 32.9, 'text': 'So we can have a list of strings like this, and then assign it to a variable like letters.', 'start': 27.238, 'duration': 5.662}, {'end': 38.925, 'text': 'We can also have a list of numbers, booleans, or even a list of lists.', 'start': 34.844, 'duration': 4.081}, {'end': 39.905, 'text': 'Let me show you.', 'start': 39.345, 'duration': 0.56}, {'end': 41.925, 'text': 'So here we have a list.', 'start': 40.445, 'duration': 1.48}, {'end': 45.486, 'text': 'Each item in this list will be a list itself.', 'start': 42.765, 'duration': 2.721}, {'end': 49.747, 'text': "So here's the first item, which is a list of two items.", 'start': 46.186, 'duration': 3.561}, {'end': 54.287, 'text': "Now let's add another item to our main or parent list.", 'start': 50.647, 'duration': 3.64}, {'end': 58.028, 'text': 'This item is also a list with two items.', 'start': 55.008, 'duration': 3.02}, {'end': 62.949, 'text': 'So now we have a matrix, which is a two-dimensional list.', 'start': 58.648, 'duration': 4.301}, {'end': 65.394, 'text': 'Now let me show you some cool tricks.', 'start': 63.973, 'duration': 1.421}, {'end': 68.796, 'text': "Let's say you want to have a list of 100 zeros.", 'start': 65.994, 'duration': 2.802}, {'end': 71.278, 'text': "You don't want to manually create that like this.", 'start': 69.477, 'duration': 1.801}, {'end': 72.299, 'text': "That's very ugly.", 'start': 71.538, 'duration': 0.761}, {'end': 73.78, 'text': 'Let me show you a better way.', 'start': 72.679, 'duration': 1.101}, {'end': 79.384, 'text': 'So we define a list of one item, one zero, and then we can multiply it by 100.', 'start': 74.3, 'duration': 5.084}, {'end': 83.286, 'text': 'And the result will be this.', 'start': 79.384, 'duration': 3.902}, {'end': 83.967, 'text': 'Let me show you.', 'start': 83.406, 'duration': 0.561}, {'end': 85.888, 'text': 'Print zeros.', 'start': 84.707, 'duration': 1.181}, {'end': 88.11, 'text': 'Here it is.', 'start': 87.369, 'duration': 0.741}, {'end': 89.911, 'text': 'There you go.', 'start': 89.611, 'duration': 0.3}, {'end': 95.365, 'text': 'So using a star or an asterisk, we can repeat the items in a list.', 'start': 91.161, 'duration': 4.204}, {'end': 99.649, 'text': 'Now similarly, we can use a plus to concatenate multiple lists.', 'start': 95.926, 'duration': 3.723}, {'end': 100.57, 'text': 'Let me show you.', 'start': 100.01, 'duration': 0.56}, {'end': 105.275, 'text': "So first I'm going to change this to 5.", 'start': 100.991, 'duration': 4.284}, {'end': 111.381, 'text': "Now let's define a variable combined, which is our zeros list plus letters.", 'start': 105.275, 'duration': 6.106}, {'end': 116.969, 'text': "Let's see what happens, print, combined, you know it.", 'start': 112.967, 'duration': 4.002}], 'summary': 'Python data structures include lists, tuples, sets, and dictionaries, with examples and tricks demonstrated.', 'duration': 112.597, 'max_score': 4.372, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9OeznAkyQz4/pics/9OeznAkyQz44372.jpg'}, {'end': 177.53, 'src': 'embed', 'start': 142.784, 'weight': 4, 'content': [{'end': 145.166, 'text': 'so we have this list function.', 'start': 142.784, 'duration': 2.382}, {'end': 152.67, 'text': 'as you can see, this function takes an iterable, so we can pass any iterable here and convert it to a list earlier.', 'start': 145.166, 'duration': 7.504}, {'end': 155.132, 'text': 'you learn about the range function.', 'start': 152.67, 'duration': 2.462}, {'end': 160.836, 'text': 'this function returns a range object which is iterable, which means we can iterate or loop over it.', 'start': 155.132, 'duration': 5.704}, {'end': 168.682, 'text': 'So here we can call this function and pass 20, and with this we can create a list of numbers from 0 to 20..', 'start': 161.616, 'duration': 7.066}, {'end': 169.803, 'text': 'Let me show you.', 'start': 168.682, 'duration': 1.121}, {'end': 177.53, 'text': "So, let's store it in numbers and then print it on the terminal, there you go.", 'start': 169.883, 'duration': 7.647}], 'summary': 'List function converts any iterable to a list. range function creates an iterable range object to loop over.', 'duration': 34.746, 'max_score': 142.784, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9OeznAkyQz4/pics/9OeznAkyQz4142784.jpg'}, {'end': 258.512, 'src': 'embed', 'start': 199.026, 'weight': 5, 'content': [{'end': 208.553, 'text': "let's print chars on the terminal so you can see each character in our original string is an item in this list.", 'start': 199.026, 'duration': 9.527}, {'end': 213.257, 'text': 'So these are a few different ways to create a list in python.', 'start': 209.573, 'duration': 3.684}, {'end': 219.042, 'text': 'Now that we have a list, we can get the number of items in that list using the len function.', 'start': 213.257, 'duration': 5.785}, {'end': 223.666, 'text': 'So here we can print the len or length of chars.', 'start': 219.042, 'duration': 4.624}, {'end': 224.427, 'text': "Let's take a look.", 'start': 223.666, 'duration': 0.761}, {'end': 228.791, 'text': 'So we have 11 items in this list Over the next few lectures.', 'start': 224.467, 'duration': 4.324}, {'end': 231.353, 'text': "We'll look at various operations around lists.", 'start': 229.031, 'duration': 2.322}, {'end': 241.412, 'text': 'So So here we have a list of four items.', 'start': 231.373, 'duration': 10.039}, {'end': 246.099, 'text': 'We can use square brackets to access individual items in this list.', 'start': 241.993, 'duration': 4.106}, {'end': 249.644, 'text': "So let's print letters of zero.", 'start': 246.76, 'duration': 2.884}, {'end': 252.688, 'text': 'This will return the first item in this list.', 'start': 250.124, 'duration': 2.564}, {'end': 255.311, 'text': "So when we run this program, we'll get A.", 'start': 253.369, 'duration': 1.942}, {'end': 258.512, 'text': 'now similar to strings.', 'start': 256.733, 'duration': 1.779}], 'summary': 'Introduction to creating and accessing lists in python, with an example of a list with 11 items.', 'duration': 59.486, 'max_score': 199.026, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9OeznAkyQz4/pics/9OeznAkyQz4199026.jpg'}, {'end': 321.574, 'src': 'embed', 'start': 288.862, 'weight': 9, 'content': [{'end': 293.185, 'text': 'Now earlier in the course, you learned that we can use two indexes to slice a string.', 'start': 288.862, 'duration': 4.323}, {'end': 295.607, 'text': 'We have the exact same concept here.', 'start': 293.846, 'duration': 1.761}, {'end': 301.451, 'text': 'So we add square brackets, first index colon second index.', 'start': 296.308, 'duration': 5.143}, {'end': 307.716, 'text': 'And this will return a new list with the first three items in our original list.', 'start': 302.232, 'duration': 5.484}, {'end': 314.468, 'text': "So if we print our original list, you can see that it's not changed.", 'start': 308.236, 'duration': 6.232}, {'end': 321.574, 'text': "Now, just like strings, if you don't specify the first argument, 0 will be assumed by default.", 'start': 315.389, 'duration': 6.185}], 'summary': 'Using two indexes to slice a list returns a new list with the specified items.', 'duration': 32.712, 'max_score': 288.862, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9OeznAkyQz4/pics/9OeznAkyQz4288862.jpg'}, {'end': 368.11, 'src': 'embed', 'start': 340.442, 'weight': 10, 'content': [{'end': 348.744, 'text': 'similarly, we can also exclude the start index here, and with this syntax we can get a copy of our original list.', 'start': 340.442, 'duration': 8.302}, {'end': 350.185, 'text': 'there you go.', 'start': 348.744, 'duration': 1.441}, {'end': 354.766, 'text': 'now, when slicing a string, we can also pass a step,', 'start': 350.185, 'duration': 4.581}, {'end': 362.288, 'text': 'and this is useful in situations where you want to return every second or every third element in the original list.', 'start': 354.766, 'duration': 7.522}, {'end': 368.11, 'text': "so now, when we run this code, we'll get a and C, so B will be a skipped.", 'start': 362.288, 'duration': 5.822}], 'summary': 'Slicing lists and strings to skip elements and create copies.', 'duration': 27.668, 'max_score': 340.442, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9OeznAkyQz4/pics/9OeznAkyQz4340442.jpg'}], 'start': 4.372, 'title': 'Python data structures', 'summary': 'Provides an overview of python built-in data structures including lists, tuples, sets, and dictionaries, demonstrating their usage and manipulation techniques such as creating a two-dimensional list and concatenating lists with quantifiable examples. it also explains how to create lists in python using the list function and the range function, demonstrating the ability to combine different types of objects and obtain the length of a list, and covers accessing and modifying elements in a list, using square brackets to access individual items, modifying items, slicing a list with two indexes, and using steps to skip elements in a list.', 'chapters': [{'end': 116.969, 'start': 4.372, 'title': 'Python data structures overview', 'summary': 'Provides an overview of python built-in data structures including lists, tuples, sets, and dictionaries, demonstrating their usage and manipulation techniques such as creating a two-dimensional list and concatenating lists with quantifiable examples.', 'duration': 112.597, 'highlights': ['The chapter introduces built-in data structures in Python including lists, tuples, sets, and dictionaries, emphasizing their significance in real applications.', 'Demonstrates creating a two-dimensional list by having a list where each item is a list itself, showcasing practical application and usage of lists.', 'Illustrates the technique of using multiplication to repeat items in a list, for example, creating a list of 100 zeros with a single zero and multiplying it by 100.', 'Shows the usage of concatenation with the plus operator to combine multiple lists, exemplifying practical manipulation techniques of lists.']}, {'end': 228.791, 'start': 117.409, 'title': 'Creating lists in python', 'summary': 'Explains how to create lists in python using the list function and the range function, demonstrating the ability to combine different types of objects and obtain the length of a list, covering examples of creating lists of numbers and strings as well as utilizing the len function to determine the number of items.', 'duration': 111.382, 'highlights': ['The list function in Python can be used to create a list from an iterable, such as the range function which generates a list of numbers, with the ability to combine different types of objects within a list.', 'Demonstrates the usage of the len function to determine the number of items in a list, showcasing the ability to obtain the length of a list containing different types of objects.', 'Illustrates how the range function can be utilized to generate a list of numbers, demonstrating the creation of a list from 0 to 20 using the range function and showcasing its iterable nature.']}, {'end': 368.11, 'start': 229.031, 'title': 'List operations basics', 'summary': 'Covers accessing and modifying elements in a list, using square brackets to access individual items, modifying items, slicing a list with two indexes, and using steps to skip elements in a list.', 'duration': 139.079, 'highlights': ['We can use square brackets to access individual items in this list, such as printing letters of zero to return the first item, which will output A.', 'We can use square brackets to modify items in the list, for example, changing the first item to a capital A and then printing the entire list.', 'Slicing a list with two indexes, with the syntax first index colon second index, will return a new list with the specified items, without changing the original list.', 'When slicing a list, we can also pass a step to skip elements, demonstrated by returning every second element in the original list, resulting in A and C.']}], 'duration': 363.738, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9OeznAkyQz4/pics/9OeznAkyQz44372.jpg', 'highlights': ['The chapter introduces built-in data structures in Python including lists, tuples, sets, and dictionaries, emphasizing their significance in real applications.', 'Demonstrates creating a two-dimensional list by having a list where each item is a list itself, showcasing practical application and usage of lists.', 'Illustrates the technique of using multiplication to repeat items in a list, for example, creating a list of 100 zeros with a single zero and multiplying it by 100.', 'Shows the usage of concatenation with the plus operator to combine multiple lists, exemplifying practical manipulation techniques of lists.', 'The list function in Python can be used to create a list from an iterable, such as the range function which generates a list of numbers, with the ability to combine different types of objects within a list.', 'Demonstrates the usage of the len function to determine the number of items in a list, showcasing the ability to obtain the length of a list containing different types of objects.', 'Illustrates how the range function can be utilized to generate a list of numbers, demonstrating the creation of a list from 0 to 20 using the range function and showcasing its iterable nature.', 'We can use square brackets to access individual items in this list, such as printing letters of zero to return the first item, which will output A.', 'We can use square brackets to modify items in the list, for example, changing the first item to a capital A and then printing the entire list.', 'Slicing a list with two indexes, with the syntax first index colon second index, will return a new list with the specified items, without changing the original list.', 'When slicing a list, we can also pass a step to skip elements, demonstrated by returning every second element in the original list, resulting in A and C.']}, {'end': 626.566, 'segs': [{'end': 426.654, 'src': 'embed', 'start': 369.278, 'weight': 0, 'content': [{'end': 371.027, 'text': 'Let me show you using a better example.', 'start': 369.278, 'duration': 1.749}, {'end': 383.062, 'text': "so i'm going to delete everything here create a new list called numbers here we're going to use the list function and pass range of 20.", 'start': 372.276, 'duration': 10.786}, {'end': 388.845, 'text': "let's print our list so we get numbers 0 to 19.", 'start': 383.062, 'duration': 5.783}, {'end': 396.749, 'text': "okay, now let's see what happens when we add square brackets here with two colons and two.", 'start': 388.845, 'duration': 7.904}, {'end': 400.531, 'text': 'this will return every other element in the original list.', 'start': 396.749, 'duration': 3.782}, {'end': 405.786, 'text': 'take a look, So we get all the even numbers 0,, 2, 4, and so on.', 'start': 400.531, 'duration': 5.255}, {'end': 409.748, 'text': "That's pretty cool, isn't it? Here's another cool thing you can do here.", 'start': 406.226, 'duration': 3.522}, {'end': 415.19, 'text': "Let's change the step to negative 1.", 'start': 410.568, 'duration': 4.622}, {'end': 420.592, 'text': 'As you can see, this will return all the items in the original list, but in reverse order.', 'start': 415.19, 'duration': 5.402}, {'end': 423.973, 'text': 'So these are some useful things you can do with lists.', 'start': 421.712, 'duration': 2.261}, {'end': 426.654, 'text': "Next we'll look at unpacking lists.", 'start': 424.793, 'duration': 1.861}], 'summary': 'Using python lists, we can extract specific elements and manipulate their order, e.g., getting every other element or reversing the list.', 'duration': 57.376, 'max_score': 369.278, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9OeznAkyQz4/pics/9OeznAkyQz4369278.jpg'}, {'end': 517.861, 'src': 'embed', 'start': 487.588, 'weight': 5, 'content': [{'end': 489.91, 'text': 'This is what we call list unpacking.', 'start': 487.588, 'duration': 2.322}, {'end': 500.383, 'text': 'Now, what is important here is that the number of variables that we have on the left side of the assignment operator should be equal to the number of items we have in the list.', 'start': 490.831, 'duration': 9.552}, {'end': 507.21, 'text': 'So if we exclude third here, and run this program, we will get an error.', 'start': 500.903, 'duration': 6.307}, {'end': 511.115, 'text': 'Value error, too many values to unpack.', 'start': 507.851, 'duration': 3.264}, {'end': 517.861, 'text': 'So there are too many items in this list, and we cannot unpack it into enough variables.', 'start': 511.475, 'duration': 6.386}], 'summary': 'List unpacking requires equal variables and items; too many items cause a value error.', 'duration': 30.273, 'max_score': 487.588, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9OeznAkyQz4/pics/9OeznAkyQz4487588.jpg'}, {'end': 626.566, 'src': 'heatmap', 'start': 595.689, 'weight': 3, 'content': [{'end': 604.493, 'text': 'Remember?. We had a function like this multiply with a parameter called asterisk numbers,', 'start': 595.689, 'duration': 8.804}, {'end': 610.476, 'text': 'and then we could call this multiply with arbitrary number of arguments.', 'start': 604.493, 'duration': 5.983}, {'end': 619.341, 'text': 'So when we prefix a parameter with an asterisk, Python will get all these arbitrary arguments and pack them into a list.', 'start': 611.076, 'duration': 8.265}, {'end': 623.484, 'text': 'This is exactly what is happening on line 2.', 'start': 619.741, 'duration': 3.743}, {'end': 626.566, 'text': 'Now let me delete this other stuff.', 'start': 623.484, 'duration': 3.082}], 'summary': 'Python packs arbitrary arguments into a list using asterisk parameter.', 'duration': 58.184, 'max_score': 595.689, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9OeznAkyQz4/pics/9OeznAkyQz4595689.jpg'}], 'start': 369.278, 'title': 'Python list manipulation and unpacking', 'summary': 'Covers python list manipulation, including functions and accessing elements, with examples. it also discusses list unpacking and packing, emphasizing the importance of matching variables with items and demonstrating the use of asterisk to pack remaining items.', 'chapters': [{'end': 426.654, 'start': 369.278, 'title': 'Python list operations', 'summary': 'Covers how to manipulate lists in python, including creating a list, using list functions, and accessing specific elements with examples of returning every other element and reversing the order, demonstrating the versatility of lists.', 'duration': 57.376, 'highlights': ['Demonstrating how to return every other element in the original list using square brackets and two colons, resulting in a list of even numbers 0, 2, 4, and so on', 'Illustrating the ability to return all items in the original list in reverse order by changing the step to negative 1', "Creating a new list called 'numbers' using the list function and passing a range of 20 to print a list of numbers from 0 to 19"]}, {'end': 626.566, 'start': 434.5, 'title': 'List unpacking and packing', 'summary': 'Discusses list unpacking and packing in python, emphasizing the importance of matching the number of variables on the left side of the assignment operator with the items in the list and demonstrating the use of asterisk to pack remaining items into a separate list.', 'duration': 192.066, 'highlights': ['List unpacking involves assigning individual items from a list to different variables, while list packing involves storing remaining items in a separate list using an asterisk.', "The number of variables on the left side of the assignment operator should match the number of items in the list to avoid a 'ValueError: too many values to unpack' error.", 'Using an asterisk before a parameter in Python will pack all the arbitrary arguments into a list, similar to the packing of remaining items in list unpacking.']}], 'duration': 257.288, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9OeznAkyQz4/pics/9OeznAkyQz4369278.jpg', 'highlights': ["Creating a new list called 'numbers' using the list function and passing a range of 20 to print a list of numbers from 0 to 19", 'Demonstrating how to return every other element in the original list using square brackets and two colons, resulting in a list of even numbers 0, 2, 4, and so on', 'Illustrating the ability to return all items in the original list in reverse order by changing the step to negative 1', 'List unpacking involves assigning individual items from a list to different variables, while list packing involves storing remaining items in a separate list using an asterisk.', 'Using an asterisk before a parameter in Python will pack all the arbitrary arguments into a list, similar to the packing of remaining items in list unpacking.', "The number of variables on the left side of the assignment operator should match the number of items in the list to avoid a 'ValueError: too many values to unpack' error."]}, {'end': 834.519, 'segs': [{'end': 756.754, 'src': 'heatmap', 'start': 652.429, 'weight': 0, 'content': [{'end': 656.815, 'text': 'so first is 1, last is 9, and the rest is here.', 'start': 652.429, 'duration': 4.386}, {'end': 670.235, 'text': "so this is all about list unpacking this lecture, i'm going to show you how to loop over lists.", 'start': 656.815, 'duration': 13.42}, {'end': 672.476, 'text': 'so here we have a list of three items.', 'start': 670.235, 'duration': 2.241}, {'end': 676.197, 'text': 'we can use our four loops to loop over this list.', 'start': 672.476, 'duration': 3.721}, {'end': 685.841, 'text': 'so four letter in letters, colon, and then we print each letter, save the changes and run the code.', 'start': 676.197, 'duration': 9.644}, {'end': 687.922, 'text': 'we get a b, c.', 'start': 685.841, 'duration': 2.081}, {'end': 691.583, 'text': 'now what if we want to get the index of each item as well?', 'start': 687.922, 'duration': 3.661}, {'end': 702.737, 'text': 'well, we have a built-in function called enumerate we call it here and this will return an enumerate object which is iterable in each iteration.', 'start': 691.583, 'duration': 11.154}, {'end': 705.918, 'text': 'this enumerate object will give us a tuple.', 'start': 702.737, 'duration': 3.181}, {'end': 712.78, 'text': "let me show you so now, when we run this code, look in each iteration we're getting a tuple.", 'start': 705.918, 'duration': 6.862}, {'end': 716.801, 'text': "so a tuple, as I told you before, is like a list, but it's read only.", 'start': 712.78, 'duration': 4.021}, {'end': 718.222, 'text': 'we cannot add new items to it.', 'start': 716.801, 'duration': 1.421}, {'end': 722.785, 'text': "So in each iteration we're getting a tuple of two items.", 'start': 719.022, 'duration': 3.763}, {'end': 729.491, 'text': 'The first item in this tuple is the index, and the second item is the item at that index.', 'start': 723.166, 'duration': 6.325}, {'end': 735.876, 'text': 'So now to get the index, we can use square brackets to access the first item in this tuple.', 'start': 730.131, 'duration': 5.745}, {'end': 750.689, 'text': 'So if we print letter of 0, we will get the indexes and right next to that we can add letter of 1, So we will see the item at a given index.', 'start': 736.497, 'duration': 14.192}, {'end': 753.131, 'text': 'But this syntax is a little bit ugly.', 'start': 750.689, 'duration': 2.442}, {'end': 756.754, 'text': 'in the last lecture you learn about list unpacking.', 'start': 753.131, 'duration': 3.623}], 'summary': 'The lecture demonstrates list unpacking and loop iteration using enumerate function.', 'duration': 65.793, 'max_score': 652.429, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9OeznAkyQz4/pics/9OeznAkyQz4652429.jpg'}, {'end': 847.265, 'src': 'heatmap', 'start': 798.56, 'weight': 3, 'content': [{'end': 802.442, 'text': 'So we add another variable index now.', 'start': 798.56, 'duration': 3.882}, {'end': 809.686, 'text': 'with this we no longer have to use square brackets and we can simply print index and letter.', 'start': 802.442, 'duration': 7.244}, {'end': 812.808, 'text': "let's run this code there you go.", 'start': 809.686, 'duration': 3.122}, {'end': 814.149, 'text': "so now we don't need this anymore.", 'start': 812.808, 'duration': 1.341}, {'end': 820.574, 'text': 'So, to recap, you can use for loops to iterate over lists.', 'start': 816.553, 'duration': 4.021}, {'end': 824.596, 'text': 'If you also need the index, you should call the enumerate function.', 'start': 821.175, 'duration': 3.421}, {'end': 828.437, 'text': 'This will return an enumerate object, which is iterable.', 'start': 825.056, 'duration': 3.381}, {'end': 834.519, 'text': 'In each iteration, it will return a tuple, and you can unpack that tuple right here.', 'start': 829.037, 'duration': 5.482}, {'end': 847.265, 'text': "In this lecture I'm going to show you how to add new items to a list or remove existing items.", 'start': 842.438, 'duration': 4.827}], 'summary': 'Demonstrated usage of enumerate function and for loops for list iteration.', 'duration': 48.705, 'max_score': 798.56, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9OeznAkyQz4/pics/9OeznAkyQz4798560.jpg'}], 'start': 627.186, 'title': 'List unpacking, looping, and enumerate', 'summary': 'Covers list unpacking and looping over lists, showcasing how to obtain the first, last, and other items, and introduces the use of the enumerate function to iterate over lists, reducing the need for manual index retrieval and unpacking, providing practical examples for better understanding.', 'chapters': [{'end': 691.583, 'start': 627.186, 'title': 'List unpacking and looping', 'summary': 'Covers list unpacking, showcasing how to obtain the first, last, and other items from a list and then delves into looping over lists using for loops, demonstrating the retrieval of each letter and its index.', 'duration': 64.397, 'highlights': ['The chapter introduces list unpacking to obtain the first, last, and other items from a list, displaying the resulting items as 1, 9, and the rest.', "The lecture proceeds to demonstrate the use of for loops to iterate over a list of three items, displaying the letters 'a', 'b', 'c'.", 'The chapter also addresses obtaining the index of each item while iterating over a list using for loops.']}, {'end': 834.519, 'start': 691.583, 'title': 'Using enumerate for iteration', 'summary': 'Introduces the use of the enumerate function to iterate over lists and obtain both the index and item in each iteration, reducing the need for manual index retrieval and unpacking.', 'duration': 142.936, 'highlights': ['The enumerate function returns an enumerate object which is iterable, providing a tuple in each iteration.', 'Using enumerate eliminates the need for manual index retrieval and tuple unpacking in for loops, simplifying the code.', 'The tuple returned by enumerate contains the index and the item at that index, making it easier to access both in each iteration.']}], 'duration': 207.333, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9OeznAkyQz4/pics/9OeznAkyQz4627186.jpg', 'highlights': ['The chapter introduces list unpacking to obtain the first, last, and other items from a list, displaying the resulting items as 1, 9, and the rest.', "The lecture proceeds to demonstrate the use of for loops to iterate over a list of three items, displaying the letters 'a', 'b', 'c'.", 'The enumerate function returns an enumerate object which is iterable, providing a tuple in each iteration.', 'Using enumerate eliminates the need for manual index retrieval and tuple unpacking in for loops, simplifying the code.', 'The tuple returned by enumerate contains the index and the item at that index, making it easier to access both in each iteration.', 'The chapter also addresses obtaining the index of each item while iterating over a list using for loops.']}, {'end': 1126.207, 'segs': [{'end': 868.093, 'src': 'embed', 'start': 842.438, 'weight': 0, 'content': [{'end': 847.265, 'text': "In this lecture I'm going to show you how to add new items to a list or remove existing items.", 'start': 842.438, 'duration': 4.827}, {'end': 853.214, 'text': 'So for adding items you have two options depending on where you want to add this new item.', 'start': 848.107, 'duration': 5.107}, {'end': 858.042, 'text': 'If you want to add an item at the end of the list, you should use the append method.', 'start': 853.895, 'duration': 4.147}, {'end': 868.093, 'text': 'So earlier you learned that everything in python is an object, so we can use the dot notation to access individual functions or, more accurately,', 'start': 858.863, 'duration': 9.23}], 'summary': 'Learn how to add or remove items from a list in python.', 'duration': 25.655, 'max_score': 842.438, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9OeznAkyQz4/pics/9OeznAkyQz4842438.jpg'}, {'end': 941.414, 'src': 'heatmap', 'start': 888.333, 'weight': 0.808, 'content': [{'end': 894.599, 'text': 'Beautiful Now, if you want to add an item at a specific position, you should use the insert method.', 'start': 888.333, 'duration': 6.266}, {'end': 897.721, 'text': 'So letters that insert.', 'start': 895.159, 'duration': 2.562}, {'end': 901.125, 'text': 'we can add something at the beginning of the list.', 'start': 897.721, 'duration': 3.404}, {'end': 907.13, 'text': "so index 0, let's add a hyphen and then print the result.", 'start': 901.125, 'duration': 6.005}, {'end': 908.231, 'text': 'so this is what we get.', 'start': 907.13, 'duration': 1.101}, {'end': 911.514, 'text': 'Now for removing objects.', 'start': 909.673, 'duration': 1.841}, {'end': 913.714, 'text': 'again, you have a few different options.', 'start': 911.514, 'duration': 2.2}, {'end': 918.036, 'text': 'if you want to remove the item at the end of the list, you should use the pop method.', 'start': 913.714, 'duration': 4.322}, {'end': 931.265, 'text': "So here we call letters.pop, this will remove the letter d at the end of our list, so now let's print our letters as you can see, d is gone.", 'start': 918.716, 'duration': 12.549}, {'end': 935.729, 'text': 'You can also pass an index here to remove the item at the given index.', 'start': 931.886, 'duration': 3.843}, {'end': 941.414, 'text': 'So, if you pass 0, instead of d, this hyphen will be removed.', 'start': 936.27, 'duration': 5.144}], 'summary': 'Using insert method to add at specific position, pop method for removal.', 'duration': 53.081, 'max_score': 888.333, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9OeznAkyQz4/pics/9OeznAkyQz4888333.jpg'}, {'end': 1048.814, 'src': 'heatmap', 'start': 1003.63, 'weight': 1, 'content': [{'end': 1009.202, 'text': 'And finally, if you want to remove all the objects in the list, you should use the clear method.', 'start': 1003.63, 'duration': 5.572}, {'end': 1012.329, 'text': "Next we'll look at finding objects in a list.", 'start': 1010.184, 'duration': 2.145}, {'end': 1023.895, 'text': 'There are times that you want to find the index of a given object in a list.', 'start': 1020.014, 'duration': 3.881}, {'end': 1028.955, 'text': "So, let's say we want to find the index of letter a in our letters list.", 'start': 1024.615, 'duration': 4.34}, {'end': 1039.478, 'text': "We call letters.index and pass a, let's print the result, so this will return 0.", 'start': 1029.656, 'duration': 9.822}, {'end': 1046.653, 'text': "What if we try to get the index of an object that doesn't exist here, like d? we get a value error.", 'start': 1039.478, 'duration': 7.175}, {'end': 1048.814, 'text': 'D is not in the list.', 'start': 1047.193, 'duration': 1.621}], 'summary': 'Teaching how to find and remove objects from a list, with examples and errors.', 'duration': 57.493, 'max_score': 1003.63, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9OeznAkyQz4/pics/9OeznAkyQz41003630.jpg'}, {'end': 1110.56, 'src': 'heatmap', 'start': 1071.489, 'weight': 3, 'content': [{'end': 1078.771, 'text': 'so if D is in letters, then we will print its index.', 'start': 1071.489, 'duration': 7.282}, {'end': 1082.631, 'text': "so now we run the program and we don't get any errors.", 'start': 1078.771, 'duration': 3.86}, {'end': 1088.832, 'text': 'we also have another method that you might find useful in certain situations, and that is count.', 'start': 1082.631, 'duration': 6.201}, {'end': 1091.093, 'text': 'so letters that count.', 'start': 1088.832, 'duration': 2.261}, {'end': 1095.994, 'text': 'this will return the number of occurrences of the given item in this list.', 'start': 1091.093, 'duration': 4.901}, {'end': 1099.754, 'text': 'so when we print, the result will get zero.', 'start': 1095.994, 'duration': 3.76}, {'end': 1106.137, 'text': 'Hi guys, thank you for watching this tutorial.', 'start': 1104.136, 'duration': 2.001}, {'end': 1110.56, 'text': 'My name is Mosh Hamadani and I have tons of tutorials like this for you on my channel.', 'start': 1106.498, 'duration': 4.062}], 'summary': 'Demonstrating index and count methods with examples.', 'duration': 34.648, 'max_score': 1071.489, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9OeznAkyQz4/pics/9OeznAkyQz41071489.jpg'}], 'start': 842.438, 'title': 'Python list methods and operations', 'summary': 'Covers adding and removing items in python lists, including using the append method, and explains the concept of methods in python objects. it also covers essential python list methods such as insert, pop, remove, del, clear, index, and count, providing clear explanations and examples of their usage and outcomes.', 'chapters': [{'end': 882.708, 'start': 842.438, 'title': 'Adding and removing items in python lists', 'summary': 'Covers how to add new items to a list in python using the append method and explains the concept of methods in python objects.', 'duration': 40.27, 'highlights': ['The chapter emphasizes the use of the append method to add new items at the end of a list, demonstrating the practical application of the concept. It also explains the concept of methods in Python objects, emphasizing that functions associated with objects are referred to as methods.']}, {'end': 1126.207, 'start': 883.488, 'title': 'Python list methods', 'summary': 'Covers essential python list methods including insert, pop, remove, del, clear, index, and count, with clear explanations and examples, demonstrating their usage and outcomes.', 'duration': 242.719, 'highlights': ['The remove method is used to remove a specific item from the list, such as removing the first occurrence of a letter, and if multiple occurrences exist, only the first one will be removed.', 'The index method is utilized to find the index of a given object in a list, with a demonstration of handling scenarios where the object does not exist in the list.', 'The count method is explained as a way to determine the number of occurrences of a specific item in the list, with an example showing the count of a particular item as zero.']}], 'duration': 283.769, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9OeznAkyQz4/pics/9OeznAkyQz4842438.jpg', 'highlights': ['The append method adds new items at the end of a list.', 'The remove method removes a specific item from the list.', 'The index method finds the index of a given object in a list.', 'The count method determines the number of occurrences of a specific item.']}], 'highlights': ['The chapter introduces list unpacking to obtain the first, last, and other items from a list, displaying the resulting items as 1, 9, and the rest.', 'The append method adds new items at the end of a list.', 'The chapter introduces built-in data structures in Python including lists, tuples, sets, and dictionaries, emphasizing their significance in real applications.', 'Demonstrates creating a two-dimensional list by having a list where each item is a list itself, showcasing practical application and usage of lists.', 'The remove method removes a specific item from the list.', 'Illustrates the technique of using multiplication to repeat items in a list, for example, creating a list of 100 zeros with a single zero and multiplying it by 100.', 'Shows the usage of concatenation with the plus operator to combine multiple lists, exemplifying practical manipulation techniques of lists.', 'The list function in Python can be used to create a list from an iterable, such as the range function which generates a list of numbers, with the ability to combine different types of objects within a list.', 'The index method finds the index of a given object in a list.', 'The count method determines the number of occurrences of a specific item.']}