repeating adjacently 3 times. Let's write since we see "same pattern" repeats 3 times , we can say fruits-RPT-3
Now, how can we have a good algorithm for this. fruits-RPT-{N} should be only printed when there are "adjacent patterns".My idea so far is; I could;
set X=0 for index 0 and y=1 for index 1 and from then add X+=2 and Y+=2 so that it will search for one after another. Seems it only works WITHOUT going to last indexes. Since len(lis) will be crossed if we add up +2. So, it's not effective as well. Then, what is an effective algorithm for this.?
Thanks for reading and help!
I think you don't even need to mess with dicts, you can go through the list looking if element - 1 and element +1 are the same, you can then check element + 2 to see if they are also the same, and count that as a repetition. you can then jump you index by one and do it again. you also have to check if the index you're at is the beginning or end of the list.
It will give indexouterror
not if you check where you are at on the list.
-1 and +1 , then +2 .... And?
well, I think that's that. unless you want to check for 3 repeated sequences, and this kind of stuff.
3 is just a number, it can repeat N times or even None
No, that's not what I meant. I meant, if you want to test for 3 elements being repeated N times adjacent, you need to go n + 3, for example.
Обсуждают сегодня