1
00:00:00,510 --> 00:00:05,340
Hey, in this video, we will work on the edit and the complete case.

2
00:00:07,220 --> 00:00:13,490
So just to refresh your memory, let me show you how these two commands work currently.

3
00:00:16,430 --> 00:00:22,670
So first let me just see the list of to dos and then enter edit as a command.

4
00:00:23,180 --> 00:00:25,550
So as soon as we press edit.

5
00:00:27,150 --> 00:00:31,590
The program asks us to enter A to do so.

6
00:00:31,590 --> 00:00:33,670
That is the equivalent of this.

7
00:00:33,690 --> 00:00:36,930
This line here produces that output.

8
00:00:37,740 --> 00:00:47,850
Now, once we enter here a number, for example, if we want to edit number three, we enter three here.

9
00:00:49,950 --> 00:00:57,240
So when we enter three, our program subtracts one from three because the list indexing starts from

10
00:00:57,240 --> 00:00:57,790
zero.

11
00:00:57,810 --> 00:01:06,330
So if we enter three as a user, actually we meant to say to the item with index two because this has

12
00:01:06,330 --> 00:01:08,830
an index of zero, this is an index of one.

13
00:01:08,850 --> 00:01:11,280
This has an index of two.

14
00:01:11,580 --> 00:01:14,610
So play has an index of two.

15
00:01:14,790 --> 00:01:17,220
Therefore, we get two here.

16
00:01:19,670 --> 00:01:23,740
Then what we do is we get a new to do from the user.

17
00:01:23,750 --> 00:01:26,720
So here we go and train you to do.

18
00:01:30,970 --> 00:01:32,890
Play a game.

19
00:01:33,880 --> 00:01:35,740
Press enter.

20
00:01:39,360 --> 00:01:42,690
And once we entered play a game here.

21
00:01:42,720 --> 00:01:45,900
So play a game is part of new to do.

22
00:01:46,860 --> 00:01:49,590
And then we change in the list.

23
00:01:53,080 --> 00:01:59,560
So we changed the item with index to to that new item.

24
00:02:00,040 --> 00:02:03,220
So play will be replaced with play a game.

25
00:02:03,250 --> 00:02:09,870
Now, if we exit the program, exit press enter and then we check to dos.

26
00:02:09,880 --> 00:02:12,900
So if you want to refresh it, reload from disk.

27
00:02:12,910 --> 00:02:15,910
No changes are written in the file.

28
00:02:19,500 --> 00:02:20,160
Why?

29
00:02:20,190 --> 00:02:21,360
Well, because.

30
00:02:23,330 --> 00:02:25,310
We didn't write any files here.

31
00:02:25,310 --> 00:02:26,750
We didn't handle any files.

32
00:02:26,750 --> 00:02:29,870
So let's fix that in this video.

33
00:02:32,030 --> 00:02:35,630
No you know that you can use the with context manager or.

34
00:02:35,780 --> 00:02:37,980
But what exactly do you do here.

35
00:02:38,000 --> 00:02:40,910
Do you read or do you edit the file?

36
00:02:41,420 --> 00:02:42,620
Well, you do both.

37
00:02:42,620 --> 00:02:46,190
First, you want to open the file in read mode.

38
00:02:46,430 --> 00:02:49,610
So once you get the number from the user and you.

39
00:02:50,470 --> 00:02:52,870
Subtract one from that number.

40
00:02:54,900 --> 00:03:00,180
Then somewhere here, perhaps you want to get the existing list of to do items.

41
00:03:01,410 --> 00:03:05,610
So in here I'll get that with context manager and just copy it here.

42
00:03:06,600 --> 00:03:09,780
So that will give us the two do's in the list.

43
00:03:10,910 --> 00:03:12,830
The existing to Jews in a list.

44
00:03:13,100 --> 00:03:14,030
And then.

45
00:03:14,910 --> 00:03:22,320
We get the new tattoos here, then we replace the new to do in the list.

46
00:03:22,320 --> 00:03:26,460
So at this point, the list should have been modified.

47
00:03:27,210 --> 00:03:32,010
I can prove that to you by checking with the print function.

48
00:03:34,510 --> 00:03:35,470
To reduce.

49
00:03:36,550 --> 00:03:42,670
Let me add some extra information here is to dos existing.

50
00:03:42,670 --> 00:03:43,840
Existing to dos.

51
00:03:44,080 --> 00:03:49,510
And then another function after we modify that to do list print.

52
00:03:52,710 --> 00:03:56,280
Here is how it will be.

53
00:03:56,730 --> 00:04:02,640
And again, we print out the tattoos variable and run the program.

54
00:04:04,970 --> 00:04:08,690
Edit So we wanted to edit number three.

55
00:04:09,290 --> 00:04:15,140
And so once I press three, which corresponds to this line here.

56
00:04:18,180 --> 00:04:23,760
Then we get printed out this line and then we enter a new to do.

57
00:04:25,800 --> 00:04:28,620
Play the game, press enter.

58
00:04:28,620 --> 00:04:30,740
And here is the new list.

59
00:04:30,750 --> 00:04:34,800
So play the game is not part of the list of bots.

60
00:04:34,800 --> 00:04:37,650
You see that it's missing a backslash.

61
00:04:37,650 --> 00:04:40,260
And so let's add a backslash in here.

62
00:04:41,100 --> 00:04:48,360
So we want to replace the existing to do with new to do plus.

63
00:04:50,220 --> 00:04:52,620
Beck slash rn.

64
00:04:54,740 --> 00:04:56,840
And then we need to do something with that list.

65
00:04:56,840 --> 00:04:59,990
So we need to write that list back to the file.

66
00:04:59,990 --> 00:05:03,260
For that we need the right with context manager.

67
00:05:03,260 --> 00:05:09,170
So I'm hoping that and putting it here at the end.

68
00:05:09,170 --> 00:05:16,640
So just before the case complete line, we put that and perhaps we don't need these lines anymore,

69
00:05:16,730 --> 00:05:17,570
so.

70
00:05:19,510 --> 00:05:25,090
Remove that and this print function as well.

71
00:05:27,280 --> 00:05:29,860
And that's about the ended case.

72
00:05:29,860 --> 00:05:31,780
So I'll run this again.

73
00:05:33,910 --> 00:05:38,290
So we have these edits.

74
00:05:38,470 --> 00:05:40,270
Let's try number four.

75
00:05:40,570 --> 00:05:42,220
So that is fix.

76
00:05:43,330 --> 00:05:44,770
Fix it.

77
00:05:44,770 --> 00:05:45,700
Well.

78
00:05:47,140 --> 00:05:48,010
Show.

79
00:05:48,790 --> 00:05:49,750
And there we go.

80
00:05:49,750 --> 00:05:50,140
Fix it.

81
00:05:50,140 --> 00:05:55,210
Well, is now number four exit check to make sure in the file.

82
00:05:55,210 --> 00:05:55,900
Yeah, fix it.

83
00:05:55,900 --> 00:05:57,880
Well, it's here, so it's working.

84
00:05:58,300 --> 00:06:04,780
And let's also implement the complete case because this is also not connected to our file.

85
00:06:05,800 --> 00:06:08,440
So we get the input from the user.

86
00:06:08,470 --> 00:06:09,760
That's the index.

87
00:06:10,390 --> 00:06:14,200
We remove that index from the list of boards.

88
00:06:14,200 --> 00:06:17,710
We want to get the current list from the file again.

89
00:06:17,710 --> 00:06:25,210
So again, we need this two lines.

90
00:06:25,990 --> 00:06:34,600
So we get the current lists, we remove the item with that index from the list and then we write the

91
00:06:34,600 --> 00:06:39,580
list back to the file using that code.

92
00:06:42,220 --> 00:06:46,930
So paste it here and let's run.

93
00:06:48,760 --> 00:06:51,720
So let's see what we have right then.

94
00:06:51,730 --> 00:06:52,960
Say complete.

95
00:06:54,190 --> 00:06:55,810
Which one do you want to complete?

96
00:06:55,930 --> 00:07:00,280
Three Press enter show.

97
00:07:02,940 --> 00:07:05,280
So play is not there anymore.

98
00:07:05,680 --> 00:07:10,500
And let's exit and go to to Deuce.

99
00:07:10,740 --> 00:07:12,660
And your play has disappeared.

100
00:07:13,410 --> 00:07:22,290
If you want to make this complete comments more user friendly, perhaps you may want to show a message

101
00:07:22,290 --> 00:07:23,210
to the user.

102
00:07:23,220 --> 00:07:32,610
So I'll write a message f string construct and have string here and say to do.

103
00:07:35,810 --> 00:07:43,470
So we want to tell the user that this to do was removed from the list.

104
00:07:43,490 --> 00:07:45,040
So which is it to do?

105
00:07:45,310 --> 00:07:55,160
Well, the removed to do, we can get it using list indexing so we get the number here, the index from

106
00:07:55,160 --> 00:07:57,650
the user and then we get the lists.

107
00:07:57,650 --> 00:08:05,480
And before we removing that to do from the list, we want to access it to store it in a variable.

108
00:08:09,850 --> 00:08:20,350
Removed to do all you can say, to do to remove because removed do doesn't make so much sense here since

109
00:08:20,350 --> 00:08:25,690
it has not been removed at this point from the list here it is removed actually.

110
00:08:25,780 --> 00:08:29,520
So let's say to do to remove is equal to to dos.

111
00:08:32,600 --> 00:08:35,929
Number minus one.

112
00:08:39,179 --> 00:08:44,010
Or you could also say create a new variable here.

113
00:08:44,010 --> 00:08:53,730
Index is equal to number minus one so that you don't have to perform this operation two times in the

114
00:08:53,730 --> 00:08:54,240
code.

115
00:08:54,240 --> 00:09:01,800
You just perform it once a year and then you replace this to that variable and also this to that variable.

116
00:09:02,430 --> 00:09:09,270
So that's the beauty of variables and that will give us a to do to remove, which was play in our case.

117
00:09:09,270 --> 00:09:16,560
And then we place that to do in here and that should do it.

118
00:09:16,710 --> 00:09:23,250
So let's run this again complete or let's show first, then complete.

119
00:09:23,490 --> 00:09:26,040
Let's try number to show her.

120
00:09:29,130 --> 00:09:33,030
We didn't get any output because I forgot to print out the message.

121
00:09:33,030 --> 00:09:33,960
So print.

122
00:09:36,290 --> 00:09:37,040
Message.

123
00:09:37,790 --> 00:09:38,720
Run again.

124
00:09:40,160 --> 00:09:46,580
Show complete so that to do was completed, but it was not printed out.

125
00:09:48,190 --> 00:09:51,400
Complete number two.

126
00:09:52,720 --> 00:09:58,390
And so we get this to the fix it well was removed from the list.

127
00:10:00,820 --> 00:10:02,800
Now you see this brake line here?

128
00:10:04,620 --> 00:10:09,120
If you want to remove that brick line, you want to go back in here.

129
00:10:10,610 --> 00:10:23,690
And say to dos that index dot strip and then goes backslash and so does this make sense to you?

130
00:10:24,230 --> 00:10:27,440
Well, the idea is that this is a string, right?

131
00:10:28,880 --> 00:10:31,470
So the situation here is like this.

132
00:10:31,490 --> 00:10:33,530
We have a list to dos.

133
00:10:37,790 --> 00:10:42,350
You know, item one, item two and so on.

134
00:10:42,350 --> 00:10:52,730
So to DOS one, that's strip, what you're doing is actually applying the strip method to that string.

135
00:10:52,970 --> 00:10:58,400
So that was just to be clear, you understand this and that's the final code.

136
00:10:58,400 --> 00:11:00,680
So let me run it for one more time.

137
00:11:01,520 --> 00:11:03,770
Show complete.

138
00:11:03,770 --> 00:11:10,730
We want to complete number two this time and we get this message to do right was removed from the list

139
00:11:11,330 --> 00:11:16,570
so that message is printed out correctly and that finishes this video.

140
00:11:16,580 --> 00:11:18,080
Thanks a lot for following.

141
00:11:18,080 --> 00:11:18,470
I'll see you.

