1
00:00:00,610 --> 00:00:04,720
Sometimes you will want to use the value of an item after you remove it from a list.

2
00:00:05,230 --> 00: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

3
00:00:12,910 --> 00:00:15,460
can draw an explosion at that position.

4
00:00:15,460 --> 00:00:21,370
So in a web application, you might want to remove a user from a list of active members and then add

5
00:00:21,370 --> 00:00:23,800
that user to a list of inactive members.

6
00:00:24,770 --> 00:00:34,940
So the Pope method removes the last item in a list, but it lets you work with that item after removing

7
00:00:34,940 --> 00:00:35,210
it.

8
00:00:35,210 --> 00: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

9
00:00:41,870 --> 00:00:43,250
top of the stack.

10
00:00:43,250 --> 00:00:48,200
So in this analogy, the top of stack corresponds to the end of the list.

11
00:00:48,200 --> 00:00:50,750
So let's pop a pop.

12
00:00:52,690 --> 00:00:55,870
Let's actually use the car models right now.

13
00:00:55,870 --> 00:00:57,400
Let's use the car models.

14
00:00:57,400 --> 00:00:58,960
Let's delete all of this.

15
00:00:58,990 --> 00:01:04,180
We will create the car models, so car models here.

16
00:01:04,180 --> 00:01:08,860
So we will make the BMW Mercedes.

17
00:01:12,160 --> 00:01:13,270
So Toyota.

18
00:01:16,070 --> 00:01:17,950
And Suzuki.

19
00:01:17,960 --> 00:01:18,440
Right?

20
00:01:21,720 --> 00:01:31,710
After that, we will print our car models, and after that we will pop, pop car models here.

21
00:01:31,980 --> 00:01:32,700
Pop.

22
00:01:35,640 --> 00:01:36,540
Models.

23
00:01:37,140 --> 00:01:41,320
And here we will add the car models that pop.

24
00:01:42,410 --> 00:01:45,860
So after that, we will print the car models.

25
00:01:49,880 --> 00:01:50,840
Car models.

26
00:01:50,840 --> 00:01:54,980
And after that, we will print the pop car models as well.

27
00:01:58,990 --> 00:01:59,470
That's it.

28
00:01:59,860 --> 00:02:01,300
Now let's run the code.

29
00:02:01,570 --> 00:02:03,160
And here.

30
00:02:03,610 --> 00:02:09,700
So we start by defining and printing the list of car models.

31
00:02:09,880 --> 00:02:12,710
Then we pop a value from the list.

32
00:02:12,730 --> 00:02:14,830
Let's actually connect them.

33
00:02:14,830 --> 00:02:16,630
So this is the first.

34
00:02:17,080 --> 00:02:18,280
So this is the.

35
00:02:18,280 --> 00:02:19,120
I'm sorry.

36
00:02:19,360 --> 00:02:20,890
Let's let me fix that.

37
00:02:20,890 --> 00:02:25,990
So this is the first code and this is the first code here.

38
00:02:27,520 --> 00:02:29,380
This is the second print statement.

39
00:02:31,090 --> 00:02:33,220
This is the second print statement here.

40
00:02:34,680 --> 00:02:35,910
And this is the third.

41
00:02:37,190 --> 00:02:40,160
This is the third print statement.

42
00:02:40,840 --> 00:02:48,400
And here we start by defining and printing the list of car models.

43
00:02:48,490 --> 00:02:55,320
And after that, then we pop a value from the list with this command.

44
00:02:55,330 --> 00:02:59,770
Here we pop a value from the list.

45
00:02:59,800 --> 00:03:00,730
That's it.

46
00:03:02,310 --> 00:03:05,730
Uh, with, uh, with this pop comment here.

47
00:03:06,000 --> 00:03:06,780
Right.

48
00:03:06,780 --> 00:03:08,460
And after that.

49
00:03:10,310 --> 00:03:10,910
So.

50
00:03:12,170 --> 00:03:14,690
And assign that value to the variable.

51
00:03:15,470 --> 00:03:22,070
So we are assigning this port here to this newly created port car models variable.

52
00:03:22,190 --> 00:03:25,850
And then we print the port variable.

53
00:03:25,910 --> 00:03:32,360
So firstly, we print a list to show that the value has been removed from the list with this.

54
00:03:33,210 --> 00:03:36,600
Uh, with this line of code here.

55
00:03:36,600 --> 00:03:38,130
And after that.

56
00:03:38,130 --> 00:03:40,500
After that, we print the list.

57
00:03:41,100 --> 00:03:44,340
We print the popped value here.

58
00:03:44,370 --> 00:03:46,110
This is the popped value here.

59
00:03:46,860 --> 00:03:49,140
Then we print the popped value here.

60
00:03:51,680 --> 00:03:52,550
That's it.

61
00:03:54,600 --> 00:03:59,370
This is the value that has been removed from the list.

62
00:04:00,610 --> 00:04:01,600
Value.

63
00:04:03,620 --> 00:04:05,390
Value removed.

64
00:04:06,530 --> 00:04:07,370
Remove.

65
00:04:08,120 --> 00:04:09,800
So in this case.

66
00:04:10,710 --> 00:04:17,370
This popped car models is not list so not.

67
00:04:18,140 --> 00:04:19,430
List, right?

68
00:04:19,460 --> 00:04:23,780
This is just a variable that's popped from the car models.

69
00:04:23,780 --> 00:04:30,980
In this case, the last one was Suzuki, so the Suzuki was popped from.

70
00:04:31,860 --> 00:04:40,320
This list and the output shows that the value susuki was removed from the end of the list and is now

71
00:04:40,320 --> 00:04:44,310
assigned to the variable popped car models.

72
00:04:44,310 --> 00:04:45,120
That's it.

73
00:04:45,120 --> 00:04:55,260
But here in this list, the new new car model list, we don't have Suzuki anymore here, so how might

74
00:04:55,290 --> 00:04:57,270
this pop method be useful?

75
00:04:57,270 --> 00:04:57,570
Right?

76
00:04:57,570 --> 00:05:05,280
Imagine that the car models in the list are stored in a chronological order according to when we owned

77
00:05:05,310 --> 00:05:05,790
them.

78
00:05:05,910 --> 00: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.

79
00:05:15,690 --> 00:05:21,000
And the output is simple sentence about the most recent motorcycle here.

80
00:05:21,000 --> 00:05:29,640
So now let's actually create that output now and I think we can delete delete this drawing now.

81
00:05:29,670 --> 00:05:38,080
I hope this helped us help helped you to understand how the logic works here with this pop here and

82
00:05:38,080 --> 00:05:38,950
now.

83
00:05:38,950 --> 00:05:40,150
We will pop.

84
00:05:40,660 --> 00:05:41,920
We will firstly.

85
00:05:43,610 --> 00:05:43,940
Right.

86
00:05:44,330 --> 00:05:44,720
Right.

87
00:05:44,720 --> 00:05:45,470
So.

88
00:05:49,010 --> 00:05:49,820
We have.

89
00:05:51,240 --> 00:05:55,500
Car models and let's actually delete this, our old code now.

90
00:05:55,500 --> 00:05:58,110
And we already created the car models list.

91
00:05:58,140 --> 00:06:00,630
We will do something a bit different here.

92
00:06:00,630 --> 00:06:03,480
So last owned or.

93
00:06:03,480 --> 00:06:05,340
Yeah, last on this.

94
00:06:05,340 --> 00:06:05,940
Okay.

95
00:06:05,940 --> 00:06:12,150
And here we will motorcycles, car models that pop here.

96
00:06:12,660 --> 00:06:17,670
As you remember, this will take the Suzuki down here.

97
00:06:18,810 --> 00:06:22,740
So now we will pop the Suzuki here.

98
00:06:22,740 --> 00:06:27,900
And after that print the F here, we will also we will use format here.

99
00:06:28,320 --> 00:06:34,650
So now the last car, The last car, last.

100
00:06:34,650 --> 00:06:37,080
I'm sorry for the ticking of the keyboard.

101
00:06:37,260 --> 00:06:38,550
So the last.

102
00:06:39,960 --> 00:06:41,100
Car model.

103
00:06:41,400 --> 00:06:42,360
Model.

104
00:06:43,520 --> 00: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

105
00:06:54,800 --> 00:06:56,210
have the title here.

106
00:06:56,210 --> 00:07:01,580
So the first letter uppercase we will write it like so it will look nice, right?

107
00:07:02,060 --> 00:07:03,440
And that's it.

108
00:07:03,470 --> 00:07:05,660
Now we will run this.

109
00:07:05,660 --> 00:07:10,400
And as you can see here, the last car model I owned was a Suzuki.
