Похожие чаты

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 ответов

10 просмотров

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.

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

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

Какой-то там пердун в 90-х решил, что есть какая-то разная типизация. Кого вообще это волнует?
КТ315
49
Hi. Do we have a raid bot? Why nobody doing raids on X? Even RH mentioned this and nobody paying attention...whats the channel for hex memes? If mods cant run raids just insta...
H
31
Подскажите, а есть vault lite или ченить такое?) А то нужен вольт для похода в вольт, но весит он ~500 мб) как-то многовато для парочки запросов ))
Alexandr Orloff
17
блеать, почему так?? где в роутере это исправляется?
Арсен Маньяков 🇦🇲
16
void terminal_scroll() { memmove(terminal_buffer, terminal_buffer + VGA_WIDTH, buffer_size - VGA_WIDTH); memset(terminal_buffer + buffer_size - VGA_WIDTH, 0, VGA_WIDTH); ...
Егор
47
🌊 Ocean Nodes Dashboard Update 🚀 Hey, Oceaners! First off, a massive round of applause 👏to all of you for the amazing engagement since we launched Ocean Nodes. In just a few ...
KreigDK | Never DM first🌊
3
Всем привет! Подскажите, пожалуйста, в чем ошибка? Настраиваю подключение к MySQL. Либы лежат рядом с exe. Все как по "учебнику"
Евгений
16
А можете как-то проверить меня по знаниям по ассемблеру?
A A
132
Здравствуйте! У меня появилась возможность купить книгу "Изучай Haskell во имя добра!". Но я где-то слышал, что эта книга устарела. Насколько это правда??
E
22
люди, которые используют flameshot, к вам вопрос. Можно-ли поставить хоткей на создание скриншота? В программе есть отдел "горячие клавиши", но там все для редактирования, скр...
ThunDer104
11
Карта сайта