1 00:00:00,920 --> 00:00:07,580 Most lists you create will be dynamic, meaning you will build a list and then add and remove elements 2 00:00:07,580 --> 00:00:09,980 from it as your program runs its course. 3 00:00:10,100 --> 00:00:15,590 For example, you might create a game in which your player has to shoot aliens out of the sky. 4 00:00:15,860 --> 00:00:21,800 You could store the initial set of aliens in a list and or remove an alien from the list each time one 5 00:00:21,800 --> 00:00:23,120 is shot down. 6 00:00:23,120 --> 00:00:27,680 So each time a new alien appears on the screen, you add it to the list. 7 00:00:27,710 --> 00:00:35,150 Your list of aliens will increase and decrease in length throughout the course of the game. 8 00:00:35,150 --> 00:00:42,290 So now the syntax of for modifying an element is similar to the syntax for accessing an element. 9 00:00:42,290 --> 00:00:49,700 Unless you change an element, you use the name of the list followed by the index index of the element 10 00:00:49,700 --> 00:00:56,690 you want to change and then provide the new value and you want to item to have. 11 00:00:56,720 --> 00:01:00,960 For example, say we have a list of course, topics. 12 00:01:01,870 --> 00:01:02,050 On. 13 00:01:02,050 --> 00:01:04,600 The first item in the list is car. 14 00:01:05,610 --> 00:01:08,130 The car is not actually called subject name, right? 15 00:01:08,130 --> 00:01:15,780 So we can change the value of this first item after the list has been created. 16 00:01:15,990 --> 00:01:19,230 So now we will use the. 17 00:01:20,850 --> 00:01:22,320 Course topics. 18 00:01:22,590 --> 00:01:23,280 Right. 19 00:01:25,220 --> 00:01:27,680 Power is the zeroth element. 20 00:01:28,340 --> 00:01:33,470 Index is zero and we will make this car repair. 21 00:01:33,500 --> 00:01:36,470 The car repair is actually like a course topic, right? 22 00:01:36,620 --> 00:01:37,410 That's it. 23 00:01:37,430 --> 00:01:41,930 So now we will print the. 24 00:01:42,740 --> 00:01:43,430 Course. 25 00:01:43,430 --> 00:01:45,650 Or let's actually print the. 26 00:01:46,400 --> 00:01:48,880 Course Topics and index zero. 27 00:01:48,880 --> 00:01:50,140 Let's print the car repair. 28 00:01:50,140 --> 00:01:50,740 Right. 29 00:01:51,370 --> 00:01:53,230 Let's know how it affected here. 30 00:01:53,230 --> 00:01:56,890 As you can see here, car repair has changed. 31 00:01:56,890 --> 00:02:01,330 Here we define the the course topics with. 32 00:02:02,160 --> 00:02:02,420 Car. 33 00:02:02,580 --> 00:02:03,910 Car as the first element. 34 00:02:03,920 --> 00:02:08,340 And we change the value of the first item to car repair. 35 00:02:08,360 --> 00:02:15,380 The output shows the first item has been changed while the rest of the list stays the same. 36 00:02:15,710 --> 00:02:19,160 So you can change the value of any item in a list, not just the first item. 37 00:02:19,160 --> 00:02:20,560 For example, let's. 38 00:02:21,290 --> 00:02:24,030 2012. 39 00:02:24,050 --> 00:02:27,800 So instead of it changing to car repair, we will make it. 40 00:02:28,460 --> 00:02:31,250 Let's actually make it the. 41 00:02:33,490 --> 00:02:34,510 Kotlin, right? 42 00:02:34,540 --> 00:02:35,370 Kotlin. 43 00:02:35,380 --> 00:02:36,730 Let's try it now. 44 00:02:36,730 --> 00:02:42,100 And as you can see here, oops, We need to also change the print function because we are now seeing 45 00:02:42,100 --> 00:02:44,740 the elements zero, not two. 46 00:02:44,920 --> 00:02:48,160 And as you can see here, we have a Kotlin. 47 00:02:49,520 --> 00:02:54,110 So also you want want to add a new element to a list for many reasons, right? 48 00:02:54,110 --> 00:03:01,120 So, for example, you might want to make a new aliens this funny aliens to appear in a game. 49 00:03:01,130 --> 00:03:08,180 Now you add a new data to a visualization or add a new registered users to make a website your build. 50 00:03:08,180 --> 00:03:14,540 So Python provides several ways to add new data to existing lists. 51 00:03:15,740 --> 00:03:20,240 So now let's let's start with the appending element. 52 00:03:20,250 --> 00:03:21,700 So the end of the list, right? 53 00:03:21,710 --> 00:03:26,120 So now we can also delete this alias here. 54 00:03:26,930 --> 00:03:28,370 So here. 55 00:03:29,390 --> 00:03:34,970 The simplest way to add a new element to a list here. 56 00:03:37,190 --> 00:03:41,330 So the simplest way to add a new element to a list. 57 00:03:42,080 --> 00:03:45,330 Is to append the item to the list. 58 00:03:45,350 --> 00:03:51,650 So when you append an item to the list, the new element is added to the end of the list using the same 59 00:03:51,650 --> 00:03:53,240 list we had in the previous example. 60 00:03:53,240 --> 00:03:54,680 We will add a new element. 61 00:03:55,160 --> 00:03:56,240 New element. 62 00:03:56,420 --> 00:03:58,760 Let's make Kotlin or Swift Write. 63 00:03:59,500 --> 00:04:03,460 So now we will write course topics. 64 00:04:03,490 --> 00:04:08,080 Course Topics dot append. 65 00:04:08,320 --> 00:04:10,840 Here we will enter the Kotlin. 66 00:04:10,840 --> 00:04:13,930 Also we will make the course topics. 67 00:04:13,960 --> 00:04:18,310 Course Topics that append Swift. 68 00:04:19,460 --> 00:04:20,060 Swift. 69 00:04:20,810 --> 00:04:25,460 And we will also have course topics that append. 70 00:04:26,660 --> 00:04:28,100 C sharp or. 71 00:04:29,630 --> 00:04:30,440 C-sharp here. 72 00:04:30,800 --> 00:04:34,970 Now, what we're going to do is now there's a here. 73 00:04:35,090 --> 00:04:38,760 So let's write that down what we have as a list. 74 00:04:38,780 --> 00:04:44,390 So here we have item 012. 75 00:04:45,250 --> 00:04:46,810 Pray for. 76 00:04:51,370 --> 00:04:53,470 One, two, three, four, five. 77 00:04:55,940 --> 00:04:57,400 Of let's make it. 78 00:04:57,410 --> 00:04:58,970 Let's actually make it from here. 79 00:04:59,920 --> 00:05:04,240 Zero one, two, three, four. 80 00:05:05,590 --> 00:05:06,280 Five. 81 00:05:07,840 --> 00:05:08,320 Thanks. 82 00:05:10,650 --> 00:05:11,580 One, two. 83 00:05:13,270 --> 00:05:15,480 Three, four, five, six, seven. 84 00:05:15,490 --> 00:05:16,000 Here. 85 00:05:16,180 --> 00:05:17,770 And seven. 86 00:05:18,380 --> 00:05:21,860 So here we will make this like that. 87 00:05:27,810 --> 00:05:28,260 Here. 88 00:05:40,660 --> 00:05:41,230 So. 89 00:05:42,240 --> 00:05:43,440 In first list. 90 00:05:44,790 --> 00:05:47,160 Remember, we had the. 91 00:05:47,950 --> 00:05:49,330 Actually here. 92 00:05:49,330 --> 00:05:52,450 So in verses we have car right? 93 00:05:52,600 --> 00:05:53,410 Car. 94 00:05:56,400 --> 00:05:56,910 Are. 95 00:05:58,260 --> 00:06:00,060 The first is Kotlin. 96 00:06:01,060 --> 00:06:02,500 I will make it short. 97 00:06:02,830 --> 00:06:05,350 Kotlin or Android. 98 00:06:05,350 --> 00:06:07,540 Here A and. 99 00:06:10,170 --> 00:06:12,600 Here and Java here. 100 00:06:14,570 --> 00:06:16,070 Var python. 101 00:06:21,330 --> 00:06:26,170 And digital forensics DVR. 102 00:06:26,280 --> 00:06:27,660 I will make it short here. 103 00:06:29,820 --> 00:06:30,100 Was. 104 00:06:37,570 --> 00:06:38,050 He. 105 00:06:40,630 --> 00:06:41,020 He. 106 00:06:43,130 --> 00:06:44,660 Are digital forensics. 107 00:06:45,140 --> 00:06:50,600 And here remember we added here items, right? 108 00:06:54,300 --> 00:06:57,150 So these items were Kotlin. 109 00:06:57,270 --> 00:07:00,750 So remember, Kotlin added first year. 110 00:07:00,750 --> 00:07:02,910 So after this we are adding Kotlin. 111 00:07:02,910 --> 00:07:05,640 So the Kotlin will be added first. 112 00:07:05,640 --> 00:07:07,950 In this case, it's going to be Remember what? 113 00:07:09,350 --> 00:07:10,030 Remember? 114 00:07:10,040 --> 00:07:10,640 Remember? 115 00:07:10,640 --> 00:07:11,120 Yeah. 116 00:07:11,150 --> 00:07:14,210 Kotlin is going to be fifth item on the list index. 117 00:07:16,250 --> 00:07:16,700 But. 118 00:07:17,560 --> 00:07:17,950 Lynn. 119 00:07:19,010 --> 00:07:19,460 Or no? 120 00:07:19,460 --> 00:07:19,880 Yes. 121 00:07:19,880 --> 00:07:21,170 Kotlin here. 122 00:07:21,170 --> 00:07:23,690 And we also have the swift here. 123 00:07:24,080 --> 00:07:27,140 It's gonna it's added secondly. 124 00:07:28,440 --> 00:07:30,960 So are we going to make it six item? 125 00:07:33,820 --> 00:07:34,090 We're. 126 00:07:35,010 --> 00:07:42,030 Because as you remember here, this function appends at the end of the list. 127 00:07:42,270 --> 00:07:47,580 So if you Kotlin ends here, here, Kotlin is here. 128 00:07:47,760 --> 00:07:49,440 After that, we are adding sweat. 129 00:07:49,440 --> 00:07:59,340 So Cutlan Swift is after Kotlin and we add the C sharp because C sharp is after the swift. 130 00:07:59,580 --> 00:08:00,150 So. 131 00:08:00,150 --> 00:08:02,910 And we also have C sharp here. 132 00:08:04,540 --> 00:08:05,410 That's it. 133 00:08:05,440 --> 00:08:09,930 Here we add the append method. 134 00:08:09,940 --> 00:08:17,250 Add three items to the end of the list without affecting any other elements in the list. 135 00:08:17,260 --> 00:08:20,890 So the append method makes it easy to build the list dynamically. 136 00:08:20,890 --> 00:08:26,950 For example, you can start with an empty list and then add items to the list using series of append 137 00:08:26,950 --> 00:08:28,620 calls using an empty list. 138 00:08:28,630 --> 00:08:35,230 Let's add the elements to our core, to our list here. 139 00:08:35,230 --> 00:08:38,140 So now let me look at the first lecture. 140 00:08:38,140 --> 00:08:39,490 Yeah, that's okay. 141 00:08:39,550 --> 00:08:46,330 So now we will instead of this, we will add and also use this here. 142 00:08:46,780 --> 00:08:49,210 So now we will create a new list. 143 00:08:51,390 --> 00:08:58,050 Actually, let's actually, instead of let's print the list course topics to show you what changed. 144 00:08:58,080 --> 00:08:58,950 Seven. 145 00:09:00,310 --> 00:09:02,190 And as you can see, it's C-sharp. 146 00:09:02,380 --> 00:09:05,470 Six is swift. 147 00:09:08,960 --> 00:09:11,480 The fifth is Kotlin. 148 00:09:11,510 --> 00:09:12,500 The fourth is. 149 00:09:12,530 --> 00:09:14,750 And as you can see, these are not changed. 150 00:09:14,780 --> 00:09:16,100 Affected by the change. 151 00:09:16,880 --> 00:09:18,110 These are not here. 152 00:09:18,110 --> 00:09:20,240 And as you can see, one. 153 00:09:20,330 --> 00:09:21,560 Lastly, zero. 154 00:09:25,110 --> 00:09:26,010 Now. 155 00:09:26,950 --> 00:09:31,330 I will take this note here and I will share this file with you. 156 00:09:33,190 --> 00:09:39,120 Now here we will delete these quotes here and instead we will add course. 157 00:09:39,920 --> 00:09:42,370 Or let's actually course names, right? 158 00:09:42,580 --> 00:09:45,910 Course names or courses here. 159 00:09:45,950 --> 00:09:48,130 Oxley Courses. 160 00:09:48,800 --> 00:09:52,480 And here we will make the list. 161 00:09:52,490 --> 00:09:52,940 Right. 162 00:09:52,940 --> 00:09:53,780 So. 163 00:09:54,660 --> 00:09:59,880 If you do write this code, this will create the. 164 00:10:00,960 --> 00:10:01,890 This will. 165 00:10:06,720 --> 00:10:07,590 I'm sorry. 166 00:10:08,480 --> 00:10:11,780 So this will create. 167 00:10:13,260 --> 00:10:14,370 Empty list. 168 00:10:21,490 --> 00:10:26,800 This will create an empty list here and you can add or delete later. 169 00:10:27,610 --> 00:10:35,110 So now, since we created this, the append method makes it easy to build list dynamically. 170 00:10:35,290 --> 00:10:38,380 So now we will use auxiliary courses. 171 00:10:38,380 --> 00:10:41,740 So the courses that append, we will add new course. 172 00:10:41,740 --> 00:10:42,310 Right? 173 00:10:42,670 --> 00:10:47,500 Android Kotlin training in 33 hours. 174 00:10:50,590 --> 00:11:00,850 And here after that we will Oxley courses that append Python training best Python course in the world. 175 00:11:00,850 --> 00:11:01,450 Right? 176 00:11:01,720 --> 00:11:04,120 In the world. 177 00:11:06,320 --> 00:11:08,330 The excellent courses that are pending. 178 00:11:09,170 --> 00:11:14,900 Ethical hacking with Python in 20 hours. 179 00:11:17,070 --> 00:11:17,560 Oxley. 180 00:11:18,720 --> 00:11:21,870 Oxley courses that append and we will make. 181 00:11:22,020 --> 00:11:24,270 It's actually right. 182 00:11:26,820 --> 00:11:27,900 Designing. 183 00:11:29,490 --> 00:11:35,040 Database models with my SQL. 184 00:11:35,770 --> 00:11:36,600 That's it. 185 00:11:36,610 --> 00:11:40,390 Now we will write print this down. 186 00:11:42,090 --> 00:11:42,630 Here. 187 00:11:43,020 --> 00:11:44,130 Let's print. 188 00:11:45,350 --> 00:11:47,960 Oxer the courses and one. 189 00:11:48,870 --> 00:11:51,410 Best courses in the world, best Python courses in the world. 190 00:11:51,420 --> 00:11:52,830 This is the first year. 191 00:11:53,010 --> 00:11:56,550 So actually this number is zero one. 192 00:11:57,410 --> 00:11:57,840 Two. 193 00:11:58,280 --> 00:11:58,790 Three. 194 00:12:03,630 --> 00:12:09,300 Now we will write zero under coding training in 33 hours. 195 00:12:09,510 --> 00:12:12,330 One Python course in the world. 196 00:12:12,750 --> 00:12:22,860 Two Ethical hacking with Python and 20 hours three designing database models with MySQL. 197 00:12:22,890 --> 00:12:30,990 So building list this way is very common because you often want to know the data your users want to 198 00:12:30,990 --> 00:12:33,630 store in a program until after the program is running, right? 199 00:12:33,630 --> 00:12:42,510 So to put your users in control, start by defining an empty list that still hold the user's value. 200 00:12:42,510 --> 00:12:46,800 Then append each new value provided to the list you just created here.