How to stop iteration

Nitin Pawar nitinpawar432 at gmail.com
Sun Jun 5 11:24:07 EDT 2011


check length of input string with if stri.len > 3

On Sun, Jun 5, 2011 at 8:35 PM, Ganapathy Subramanium <
sganapathy.subramanium at gmail.com> wrote:

> 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
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


-- 
Nitin Pawar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110605/344641c2/attachment.html>


More information about the Python-list mailing list