Compare Characters
00:00
Now I want to compare these, do something like if first
is different from second
00:08
or first
is different from third
, and so on. But I think I’ll, instead of continuing like this, I’ll do something quite similar, and I’ll just say that if any of these comparisons are True
, so I’m kind of reversing them.
00:28
So if first
is equal to second
, or first
is equal to third
, or first
is equal to fourth
,
00:40
or let’s see, second
is equal to third
, or second
, and now I’m kind of, I’ll continue this soon, but I’ll just get some auto-formatting in place here.
00:53
second
is equal to fourth
. There we go. And then I think the last one we need to check is whether the third
character is equal to the fourth
character.
01:04
Yeah. So if any of these happen to be True
, that means that we haven’t found the marker because that means that they’re not all different. So let’s quickly recap the code that you have there.
01:16
So you started with an if
statement, and then you used the any()
function, and any()
checks if anything in a sequence is True
.
01:26
Yes. It’s really a fancy way of writing many or
statements together. Okay. Yeah, I think that’s a good way of saying it. So instead of what you started with or
this or
this, you just check like if any of them is True
, then there is a character appearing again in the sequence of characters.
01:46 Right? And that means that we have a repeated character, which means if we just want to move everything one step ahead.
01:55
So in that case, I’ll add 1
to my marker. So now I’m moving the number that we’re kind of reporting at the end.
02:04
Now I want to also move all the first
, second
, third
, and fourth
things ahead. So that means that my new first
character becomes what used to be the second
character.
02:16
So that means in this example, we used to have m
as the first
character, but now I’m going to want to move ahead so that j
becomes my first
character.
02:24
And this j
used to be the second
character.
02:29
So I’m just saying, okay, now first
is the old second
. Then I can continue with the same logic. So my new second
is the old third
, my new third
is the old fourth
character, and then this is where it kind of becomes slightly different.
02:46
My new fourth
character, that’s one that we need to pick up from the list of rest
characters.
02:54
So I want to do something like this, where I take it from the first rest
, but I also need to update rest
. So I’ll do this in a slightly different way, where I’ll say that rest
equals rest
like this.
03:10
So here we’re using the same star argument (*
) that we did earlier, meaning that, okay, let’s pack everything that’s left over into this variable.
03:20
So in the end, this means that fourth
will get the first p
from the list down there. And then the new rest
is kind of updated to be everything from q
and to the end.
03:31
Okay. And interesting, as well, in your code right now is that the order of the statements like first
equals second
, second
equals third
, and so on is important.
03:43
Yes, exactly. So the order is important because if we would do something like doing second
equals third
first, then we’re kind of overriding old second
before we’re actually reading it.
03:53 So these lines depend on the order that we’re spelling them out in. That is true.
Become a Member to join the conversation.