+ 1

Get indexes of specific items

Hello, I have worked in the 2D map task. I have used python. In this task I have to find out the index of the char P in a string e.g XPXPX . It can be two P in this string. Does anyone know an smart solution? https://code.sololearn.com/cVE6HoZq2akp/?ref=app

6th May 2021, 7:10 AM
Daniel
Daniel - avatar
4 Réponses
+ 4
The while loop will be better, because you want to search for the matching items only.
6th May 2021, 10:38 AM
JaScript
JaScript - avatar
+ 3
You can take a loop and searching for the first index and than begin the next time with index +1 by the search.
6th May 2021, 7:14 AM
JaScript
JaScript - avatar
+ 1
I used a for loop. But in my opinion it is not the best solution. I fought there is a smarter way with re or list functions
6th May 2021, 7:14 AM
Daniel
Daniel - avatar
0
Why not go with a for loop or recursion.
6th May 2021, 7:11 AM
Krish
Krish - avatar