In this course, you learn how to automate tasks with code. That is, have Python to repetitive things, as well as sometimes make decisions for you. In a previous course, the data you work with was always a single item, such as a single name or age or some other single piece of data. But Python has the ability using something called a list, to store multiple pieces of data together. This will make it easier to tell Python to care about repetitive tasks for you. Let's take a look at how to use lists in Python. Let's start by importing some functions that we'll use in this notebook. I'm going to hit shift, enter and load those two functions. And now let's say I want to write a poem for three of my friends. Here's how we could use a large language model to do it. I'm going to set the variable name to be the name of my first of the three friends, which is Tommy. And now here's a prompt using the f-string, which you learned about in the previous course, which says: write a four-line birthday poem for my friend. Then insert the name here. The poem should be inspired by the first letter of my friend's name. And let's run that. And so this output is: terrific, Tommy full of cheer. That's pretty cool, I like that. And I want to write these poems for three of my friends. So if I want to now go on to my second friend, I would set the variable name to now be Isabel. And then we run this. And now here's a poem for Isabel. "Infinite joy and laughter..." and so on. Wow. Another nice poem. And then finally for the third friend, Daniel, we now get: "Dashing Daniel, dear and true..." and so on. As a reminder, if you run these cells yourself, remember to run them in the same order as I was as well, because running the cells in a different order may result in an unexpected error. But you saw that this process of writing three poems was a little bit repetitive. I had to go here, set the name three times to different values, and then run the prompt and print LLM response three times. It turns out using lists in Python lets you store the name of all three friends at the same time, and then eventually we'll give you a more efficient way to generate these three poems. Let's take a look. Here's how we can create our first list. I'm going to say, friends lists. This is another variable. But this variable will take the value of a list. And this is how it works. I'm going to open square brackets. That tells Python I want to create a list. And then the first item of the list is Tommy, which as you saw from the previous course is a string. And then comma and then the second item Isabel comma and then the third item Daniel. And then lastly close square brackets here in order to tell Python that this is the end of the list. And if I were to run this, I've now created a new variable called "friends_list" that stores three pieces of data: Tommy, Isabel, and Daniel all at the same time. If you now tell Python to print "friends_list" and run that in now prints back out this list. Let's take a look at how list works. We wrote this piece of code to say Friends equals Tommy, Isabel, Daniel. And you can think of this as creating a set of little trailers or a set of little carts shown here, each of which can hold a single piece of data. So this cart little here holds the piece of data, Tommy. The next one. Isabel. And this last one, Daniel. And friends_list is like a little tractor that puts together and allows you to assemble these three little carts together, each of which has one of these three net friends names. Now, each of these little carts also has a number associated with it. That's what these numbers zero, one and two are. And where's people often start counting from one. So we said Tommy's the first name, Isabel the second and Janice's third computers and the Python programing language in particular places like counting from zero rather than counting from one. So that's why this first cart is actually numbered with zero, because I start counting from zero, not from one. And then the next one is cart number one, and then one after that is cart number two. These numbers would be important later. Well want to refer to specific items. Sometimes we say specific elements and this lists of three items. And you see later in this course they would be able to add, delete, retrieve or edit different elements or different items in this list. Let's go over the exact code needed to create a list. There is the list of a name which is friends_list. Then the equal sign to say we're going to set friends list to be equal to this list on the right. The square brackets indicates the start and end of the list. And then in the middle are the elements or the items of the list, separated by commas. So if you remember the type function, if we ask what is the type of the friends_list we created, you find that it is a list. And you remember the Len function which tells you the length of a string. It turns out you can also ask what's the length of a list? And if you run this, you can see because there are three namess in this list. Now you create a list, a source, a name is of three friends simultaneously. I can create a prompt like this. Write a set of four line birthday poems for my friends and then friends list in here. And let's print out this prompt. Right. So, write a set of four-line birthday poems for my friends. Tommy, Isabel, Daniel. And it is storing the list here in the prompt is square brackets, which maybe isn't the best written prompt, but it's okay. The large language models pretty spot and I think I'll figure it out. And if I then run print response. The LLM generates three poems. So this works. The large language model model was smart enough to understand this prompt and write three poems. Let's take a look at how to access one specific item or one specific element of the friends list. If my friends list has Tommy, Isabel, and Daniel. How to access one of the names? Well, rather than me giving the answer, why don't we ask our AI chatbot So, ask the chatbot: how to access a specific element of this list. And it tells me that you can access the first friend as friends list square brackets zero. And this outputs Tommy or Friends list. And then in square brackets one, gives us Isabel and friend_list brackets two, this gives me Daniel. So, I'm going to copy this from your chatbot. And remember this hash sign, pound sign is just a comment. So Python doesn't run anything to the right to this hash sign. And if I run this code, it prints out. Tommy. I just want to call out that here we're using square brackets, not parentheses. And if you were to run just with normal parentheses, that wouldn't work. And in fact, you would generate an error. Seeing errors is a normal part of coding, so feel free to pause this video and try this with parentheses rather than with square brackets. And you see that won't work. To print out the name of the next friend. We can also do this: print friends list and in square brackets. Friend number one. Close square brackets. Close parentheses. And now let's run that. And this prints out Isabel. And lastly, let me try one more thing. If I tell it to print friends list and then friend number three, what do you think will happen? If I ask it to print friend number three? It says: gives an error. Because in my list there is no friend number three. They're only friends number zero, one and two. And this error message says "list index out of range". Because this number three into for example, we sometimes call that the list index. And three is too large. Which is why it gives an error. Don't worry too much about what the error message here is saying. I find Python error messages sometimes a little bit cryptic. If you want it explained in a more easy to understand way, feel free to copy paste this error message into the chatbot and ask it to explain it to you. And in contrast, if you want to print out Daniel's name, I should print it as friend number two. Now, Python also gives you some nice tools to modify the elements in a list. You can add remove, edit items, and so on. So, here's the friends list and you want to add an element, you could do this. Friends list, and then dot and then append. Although let me shift enter to run that. And if I now print friends list again we now have Tommy, Isabel, Daniel. And then we just append it to the end of the list, Otto. So, encourage you to pause the video and go take this list of four friends and append another name to it to add a fifth friend to this list. Now, in addition to adding elements or adding items to list, you can also delete elements. So, let's say you're using a list to track friends you need to send birthday cards to. And Tommy has had his birthday. You've sent a card, so you can now remove him from the list. Then you could do this. Friends list dot remove Tommy. And to be clear, I still like Tommy. We're still friends. Just removing it because I've already sent him his birthday card. And if you do this and prints the new friends list, you end up with just Isabel, Daniel and Otto. And please try for yourself. Modify the code to remove one of these other names from the list and print it out to see if it gave you the right answer. Now, so far we've been using this to store strings or to store people's names. It turns out this can store other types of data as well. So, for example, if you want to store the ages of your friends, you can have a list of here three numbers three integers. If you print the list of ages, you end up with that. Later in this course, we'll use Python to help us prioritize tasks to do. So, here's a longer piece of code that says lists of tasks. And as usual, I have an open square brackets. And then here's the task Compose a brief email to my boss explaining I'll be late for tommorow's meeting. Write a birthday poem for Otto read. Write a 300-word review of the movie The Arrival. And this creates a list of three strings where each of these strings is one of these tasks. And in Python you can spread out the lists over multiple lines of code. Since this makes it a little bit easier to type and read than if all of this was in a single line. And in fact, each of these lists of tasks is something that you could do ask a large language model to do. So, one thing we could do is set tasks to be list of task zero. So now the task is: compose a brief email to my boss explaining I'll be late. And so I'm going to do that. Here's an email. If I now wanted to do the next task for me, I can have it do this: task equals list of task one. Let's have it do that. Here's my birthday poem for Otto. And then lastly, let's have it do task three for me. Which generates this review of the movie for the Arrival. And so, by writing these three snippets of code where we set task equals list of tasks, and then square brackets zero one two in turn and then printing our response to these tasks, we work through the different elements in this to-do list. But this is a little bit repetitive. We had to type and run this code three times to process each of the elements of the list separately. In fact, if you had to-do this with ten items or 20 items, typing and running this code 20 times manually would be a little bit annoying and repetitive. In the next video, you learn about a much better way to do this, a for loop, which is a way to tell Python to do a task for you over and over. Let's go on to the next video to see this in action.