Похожие чаты

I'Ve a list; lis=['orange','apple','orange','apple','orange','apple','car','bus'] In this list, we see orange and apple

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!

7 ответов

16 просмотров

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.

Пользователь-6165a Автор вопроса
Пользователь 6165a
It will give indexouterror

not if you check where you are at on the list.

Пользователь-6165a Автор вопроса
Пользователь 6165a
-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.

Пользователь-6165a Автор вопроса
Gian
well, I think that's that. unless you want to chec...

3 is just a number, it can repeat N times or even None

Пользователь 6165a
3 is just a number, it can repeat N times or even ...

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.

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта