Archive

Posts Tagged ‘slicing’

Cutting and Slicing strings in python

January 21, 2015 Leave a comment

Problem:
I needed to get alternative characters in a string.

Solution:

>>> word = “Mouse”
>>> word[::2]
‘Mue’
>>> word[1::2]
‘os’

Source:
https://stackoverflow.com/questions/20847205/program-to-extract-every-alternate-letters-from-a-string-in-python
http://www.pythoncentral.io/cutting-and-slicing-strings-in-python/

Advertisements