In this video, we will add a complete feature to our program, complete meaning allowing the user to
mark a to do item as complete as done.
So then that item will be deleted from the list of to dos.
For this, we're going to be using a case complete statement.
So if the user enters add show edit complete in case of complete, what do we want to do here?
So this is the logic here.
When you want to manipulate something in this case, we want to manipulate the list.
So if the user enters complete, we want to modify the list.
So we want to remove one item from that list.
That is a manipulation process.
And when we think about manipulation, we think about methods.
So if I was you to find out how to remove an item from a list, I would open a python console and use
the function and enter the list there.
That will give me a list of methods.
So I'll take a look here.
Perhaps I find something like remove.
Yo, here is a remove so I might then ask help for lists.
Remove to see how remove works.
So this gets a value as argument and it removes the first occurrence of value.
Value is that.
So then I'll try this.
Maybe my list is equal to.
A, B, and C.
So my lists, you know, the notation of methods that remove.
And that the value.
Well, this means by value they mean the item.
So maybe be and then try my list.
And B is gone from my list.
So that is one way to find out what methods you need.
Another way, of course, is to use Google.
So if you did a search on Google, a simple search such as methods to remove items from Python lists,
you would get some answers.
For example, here it says Clear pop remove.
So it seems there are other methods as well.
So Google search.
Some Internet research might give you more answers to your questions.
So clear and pop.
You can also find these in.
Dear.
So you see?
Clear should be here.
Here is clear and pop as well, so you might want to try this out.
Help list.
That's clear.
Remove all items.
So perhaps that is not what you need.
But anyway, this is how you learn.
So you experiment with things.
You research.
Try out, list that pop.
So in case of pop, this removes and returns item at index.
So in the case of pop, the argument is an index.
It is not the item itself.
So that means you could use pop as in my list that pop.
And if you say one here, C is removed and it is also returned.
So you see this method returned the removed item.
And if you check my list now, it only has a.
Now, perhaps you might be wondering what is minus one?
Well, this is a default value of the argument.
Meaning if you.
Half again, my list is equal to A, B and C, and you simply say my list that Pope, without any arguments,
that means minus one will be the default argument.
Minus one corresponds with the last item.
So less indexes has another system besides the default system, which means zero index for a an index
of one for B and an index of two for C, You can also specify indexes like minus one for C, minus two
for B, minus three for A, and so on.
So my list, you get that?
So we have two options to remove or pop.
Let's see which is the one we need so complete.
And then we say if the user enters complete, then we want to ask the user.
Perhaps this same question here.
So indented with tab a number is equal to and input number of the two due to edit.
Well, let's change this to complete.
So we prompt the user with an input function and we convert that the user inputs to an integer.
So the user will enter one, two or three or four.
And so we have the index of the item we want to remove to complete.
Then what we do is we point to two dos dot pop.
Number.
So that's the thing we did here as well.
We remove the item with that particular index.
So let's see how this goes.
Type add, show or edit.
Let's add some items.
Clean add.
Through show zero four.
Clean one four through.
So let's place one presenter.
And let's show now the items.
Oh, that didn't work because I entered one when I was asked to enter, add, show, edit or exit.
So I should enter complete here first and then one so complete.
Then we get asked number of the two due to complete.
Let's say one.
No.
And then we say show so clean is remained and through is removed.
Now something quick we might want to improve here is to start the list from one and not zero.
So for that, we need to go to the show case.
So from index item in enumerate, we say that index and here we say plus one.
So if we do that rerun, we say add.
Fleeing at.
Do and then show.
Now this will start from one, two and so on.
And then in edit, we subtract one so we compensate for.
That's increase and we should do the same in here.
So number minus one.
So that should be okay now.
So let's try again at do at, clean at.
Paste and.
Show.
One, two, three.
We want to complete item with index.
To so show.
Yeah.
So clean was the item within the zoo.
So we removed that item and now we have to do and paste only.
Another improvement is we want to add edit complete here or exit so that it shows in here.
Yeah, let's check that quickly.
Yeah.
Here we go.
Complete this part of the query now.
And so this completes this video.
That was the complete feature that we added.
Let's keep on improving the app while learning new Python core features.
I'll talk to you in the next video.
Thank you.