WEBVTT

00:00.610 --> 00:04.720
Sometimes you will want to use the value of an item after you remove it from a list.

00:05.230 --> 00:12.910
For example, you might want to get the A and B position of an alien that was just shot down so you

00:12.910 --> 00:15.460
can draw an explosion at that position.

00:15.460 --> 00:21.370
So in a web application, you might want to remove a user from a list of active members and then add

00:21.370 --> 00:23.800
that user to a list of inactive members.

00:24.770 --> 00:34.940
So the Pope method removes the last item in a list, but it lets you work with that item after removing

00:34.940 --> 00:35.210
it.

00:35.210 --> 00:41.870
So the term pope comes from thinking of a list as a stack of items and popping one of the item off the

00:41.870 --> 00:43.250
top of the stack.

00:43.250 --> 00:48.200
So in this analogy, the top of stack corresponds to the end of the list.

00:48.200 --> 00:50.750
So let's pop a pop.

00:52.690 --> 00:55.870
Let's actually use the car models right now.

00:55.870 --> 00:57.400
Let's use the car models.

00:57.400 --> 00:58.960
Let's delete all of this.

00:58.990 --> 01:04.180
We will create the car models, so car models here.

01:04.180 --> 01:08.860
So we will make the BMW Mercedes.

01:12.160 --> 01:13.270
So Toyota.

01:16.070 --> 01:17.950
And Suzuki.

01:17.960 --> 01:18.440
Right?

01:21.720 --> 01:31.710
After that, we will print our car models, and after that we will pop, pop car models here.

01:31.980 --> 01:32.700
Pop.

01:35.640 --> 01:36.540
Models.

01:37.140 --> 01:41.320
And here we will add the car models that pop.

01:42.410 --> 01:45.860
So after that, we will print the car models.

01:49.880 --> 01:50.840
Car models.

01:50.840 --> 01:54.980
And after that, we will print the pop car models as well.

01:58.990 --> 01:59.470
That's it.

01:59.860 --> 02:01.300
Now let's run the code.

02:01.570 --> 02:03.160
And here.

02:03.610 --> 02:09.700
So we start by defining and printing the list of car models.

02:09.880 --> 02:12.710
Then we pop a value from the list.

02:12.730 --> 02:14.830
Let's actually connect them.

02:14.830 --> 02:16.630
So this is the first.

02:17.080 --> 02:18.280
So this is the.

02:18.280 --> 02:19.120
I'm sorry.

02:19.360 --> 02:20.890
Let's let me fix that.

02:20.890 --> 02:25.990
So this is the first code and this is the first code here.

02:27.520 --> 02:29.380
This is the second print statement.

02:31.090 --> 02:33.220
This is the second print statement here.

02:34.680 --> 02:35.910
And this is the third.

02:37.190 --> 02:40.160
This is the third print statement.

02:40.840 --> 02:48.400
And here we start by defining and printing the list of car models.

02:48.490 --> 02:55.320
And after that, then we pop a value from the list with this command.

02:55.330 --> 02:59.770
Here we pop a value from the list.

02:59.800 --> 03:00.730
That's it.

03:02.310 --> 03:05.730
Uh, with, uh, with this pop comment here.

03:06.000 --> 03:06.780
Right.

03:06.780 --> 03:08.460
And after that.

03:10.310 --> 03:10.910
So.

03:12.170 --> 03:14.690
And assign that value to the variable.

03:15.470 --> 03:22.070
So we are assigning this port here to this newly created port car models variable.

03:22.190 --> 03:25.850
And then we print the port variable.

03:25.910 --> 03:32.360
So firstly, we print a list to show that the value has been removed from the list with this.

03:33.210 --> 03:36.600
Uh, with this line of code here.

03:36.600 --> 03:38.130
And after that.

03:38.130 --> 03:40.500
After that, we print the list.

03:41.100 --> 03:44.340
We print the popped value here.

03:44.370 --> 03:46.110
This is the popped value here.

03:46.860 --> 03:49.140
Then we print the popped value here.

03:51.680 --> 03:52.550
That's it.

03:54.600 --> 03:59.370
This is the value that has been removed from the list.

04:00.610 --> 04:01.600
Value.

04:03.620 --> 04:05.390
Value removed.

04:06.530 --> 04:07.370
Remove.

04:08.120 --> 04:09.800
So in this case.

04:10.710 --> 04:17.370
This popped car models is not list so not.

04:18.140 --> 04:19.430
List, right?

04:19.460 --> 04:23.780
This is just a variable that's popped from the car models.

04:23.780 --> 04:30.980
In this case, the last one was Suzuki, so the Suzuki was popped from.

04:31.860 --> 04:40.320
This list and the output shows that the value susuki was removed from the end of the list and is now

04:40.320 --> 04:44.310
assigned to the variable popped car models.

04:44.310 --> 04:45.120
That's it.

04:45.120 --> 04:55.260
But here in this list, the new new car model list, we don't have Suzuki anymore here, so how might

04:55.290 --> 04:57.270
this pop method be useful?

04:57.270 --> 04:57.570
Right?

04:57.570 --> 05:05.280
Imagine that the car models in the list are stored in a chronological order according to when we owned

05:05.310 --> 05:05.790
them.

05:05.910 --> 05:15.390
So if this is the case, we can use the pop method to print a statement about last car model we bought.

05:15.690 --> 05:21.000
And the output is simple sentence about the most recent motorcycle here.

05:21.000 --> 05:29.640
So now let's actually create that output now and I think we can delete delete this drawing now.

05:29.670 --> 05:38.080
I hope this helped us help helped you to understand how the logic works here with this pop here and

05:38.080 --> 05:38.950
now.

05:38.950 --> 05:40.150
We will pop.

05:40.660 --> 05:41.920
We will firstly.

05:43.610 --> 05:43.940
Right.

05:44.330 --> 05:44.720
Right.

05:44.720 --> 05:45.470
So.

05:49.010 --> 05:49.820
We have.

05:51.240 --> 05:55.500
Car models and let's actually delete this, our old code now.

05:55.500 --> 05:58.110
And we already created the car models list.

05:58.140 --> 06:00.630
We will do something a bit different here.

06:00.630 --> 06:03.480
So last owned or.

06:03.480 --> 06:05.340
Yeah, last on this.

06:05.340 --> 06:05.940
Okay.

06:05.940 --> 06:12.150
And here we will motorcycles, car models that pop here.

06:12.660 --> 06:17.670
As you remember, this will take the Suzuki down here.

06:18.810 --> 06:22.740
So now we will pop the Suzuki here.

06:22.740 --> 06:27.900
And after that print the F here, we will also we will use format here.

06:28.320 --> 06:34.650
So now the last car, The last car, last.

06:34.650 --> 06:37.080
I'm sorry for the ticking of the keyboard.

06:37.260 --> 06:38.550
So the last.

06:39.960 --> 06:41.100
Car model.

06:41.400 --> 06:42.360
Model.

06:43.520 --> 06:54.800
I owned was a and here we are adding the last owned right last on last owned that title in case we don't

06:54.800 --> 06:56.210
have the title here.

06:56.210 --> 07:01.580
So the first letter uppercase we will write it like so it will look nice, right?

07:02.060 --> 07:03.440
And that's it.

07:03.470 --> 07:05.660
Now we will run this.

07:05.660 --> 07:10.400
And as you can see here, the last car model I owned was a Suzuki.
