Hello all,
i'm trying to understand what should i change on my code so that i can use any words / sentence on the string:
Given a string, display only those characters which are present at an even index number.
1. My code:
result above is ok but not suitable for example if i have a string='Hello World'.
the code does not recognize that each l occupies a different index position.
thanks in advance
frederico
i'm trying to understand what should i change on my code so that i can use any words / sentence on the string:
Given a string, display only those characters which are present at an even index number.
1. My code:
Str='pynative' a=list(Str) print(a) for letter in a: index=a.index(letter) if index % 2==0: print('index=',index,'letter=', letter)2. The result:
Output:['p', 'y', 'n', 'a', 't', 'i', 'v', 'e']
index= 0 letter= p
index= 2 letter= n
index= 4 letter= t
index= 6 letter= v
3. What to do to use any word and get the correct index position?result above is ok but not suitable for example if i have a string='Hello World'.
the code does not recognize that each l occupies a different index position.
thanks in advance
frederico