How to stop iteration

Ganapathy Subramanium sganapathy.subramanium at gmail.com
Sun Jun 5 11:05:19 EDT 2011


Hi All,

I'm a new bie to programming and need some assistance in this code.

I have a function which will split the given string into 3 characters each
and I want to achieve this by recursion.

I have written the following code, but I don't know how to stop the
recursion when the length of the remaining string is less than or equal to 3
characters. Any inputs on this please?

string = 'This is a sample python programming'
space = 2
final_result = []
def strsplit(stri, spa):
    s = stri[:spa]
    final_result.append(s)
    stri = stri[spa:]
    strsplit(stri,spa)
    return final_result
c = strsplit(string,space)
print 'The final result is: ', c
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110605/2c2447b2/attachment.html>


More information about the Python-list mailing list