+ 1

How to write a loop that prints out index of every 'i' in 'Mississippi'

10th Jan 2020, 3:59 AM
Lalit kumar
Lalit kumar - avatar
4 odpowiedzi
+ 7
for idx, letter in enumerate('Mississippi'): if letter == 'i': print(idx)
10th Jan 2020, 5:34 AM
Tibor Santa
Tibor Santa - avatar
+ 7
Tibor Santa why so complicated? for i in range (len ('Mississippi') - 1): if 'Mississipi' [i] == 'i': print (i)
10th Jan 2020, 6:47 AM
Sebastian Keßler
Sebastian Keßler - avatar
+ 3
Another way::: string='Mississippi' k=0 for i in string: if(i=='i'): print(k) k=k+1
10th Jan 2020, 6:58 AM
Shobhith J B
Shobhith J B - avatar