Use Sets to Remove Duplicates
Yes, exactly. So, it’s like the length of the markers seems to be something that we should parametrize in our code. So I guess let’s do that. I’ll introduce a
marker_length variable here that we can then switch between part one and part two by changing this one between
00:52 So now my code here, I’m using the string that we have on top here, and I’m just converting this one into a set and then printing it out. And what we may be able to see here—it’s not completely obvious, I guess, since there’s so many characters—is that there are no duplicates any longer in this.
So you can see the, the order is kind of changed around a little bit, but for instance, there is a
j, which we have
j in the second and the fourth character, but in our set, there’s only one of the
01:36 So since it removes duplicates, we can use that as a test for whether there are duplicates, okay, in our character sets. So as an example of this, let’s say that we’re looking for a, let’s just call it a candidate.
And I’ll say that this will start here by just picking out the, okay, let’s use
marker_length here since we have it. So here I’m just pulling out the first four characters for the
marker_length for first four characters from the candidate.
candidate and the set of
candidate so that we can see what happens. Okay. And what you were doing there with
stream and the square brackets and the colon is you’re slicing the string from the
stream variable, which is a string from index zero to
marker_length, which is four.
Become a Member to join the conversation.