How do I remove characters from even positions in a string?

Asked

Viewed 42 times

0

I have a string and I want to remove from it only the characters in even positions

  • Welcome to Stack Overflow! Your question seems to have some problems and your experience here in Stack Overflow may not be the best because of this. We want you to do well here and get what you want, but for that we need you to do your part. Here are some guidelines that will help you: Stack Overflow Survival Guide in English.

1 answer

2

You can use a little trick list:

>>> a = "01234567"
>>> a[::2]
'0246'
>>> a[1::2]
'1357'

I put the 2 options because I don’t know if you consider the first position as odd or as even (since it is a[0])

Browser other questions tagged

You are not signed in. Login or sign up in order to post.