+ 2
Why isn't this code bit printing the characters with even index in the string properly?
Please point out the mistake. https://code.sololearn.com/ciwoAhIv2sBL/?ref=app
4 Respostas
+ 5
Noob Gamer The index() returns the index of first occurrence of specified element. So, in the case when the input is "see", the output is "s" because the first occurrence of "e" is at index 1 and when you say '_str.index("e")' it always returns 1 thereby making your condition False.
+ 6
As index in python is zero based, and zero is an even number, this code can be used:
a = 'abcdefghijkl'
print(', '.join([char for ind, char in enumerate(a) if ind %2 == 0]))
# output: a, c, e, g, i, k
(????? ??????, it seems that your code gives output from odd index)
+ 3
Thanks everyone.