2

I want to split "ranganath" into something like

"ra"
"ng"
"an"
"at"
"h"

using Python. Any help would be highly appreciated.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
sam
  • 83
  • 1
  • 9
  • possible duplcate of [Split python string every nth character?](http://stackoverflow.com/questions/9475241/split-python-string-every-nth-character) – pes502 Jun 24 '14 at 07:10
  • `s = "ranganath"; str_split = lambda word, step: [ word[i:i+step] for i in range(0, len(word), step) ]; str_split(s, 2)` > ['ra', 'ng', 'an', 'at', 'h'] – Michael Kazarian Jun 24 '14 at 07:25

1 Answers1

1

Try with:

x = 'ranganath'
[ x[i:i+2] for i in xrange(0,len(x),2) ]