How to split string in equally long parts

Oren Tirosh oren-py-l at hishome.net
Wed Apr 9 10:50:20 CEST 2003


On Wed, Apr 09, 2003 at 12:51:04AM -0700, Dan Bishop wrote:
> "Mike Rovner" <mike at bindkey.com> wrote in message news:<mailman.1049836334.25959.python-list at python.org>...
> > def split(S,N):
> >   """S - source string
> >      N - number of parts
> >   """
> >   lens=len(s)
> >   l=lens/N
> 
> Don't you mean lens//N ?

To get integer division that works consistently on all Python versions 
I would suggest int(lens/N). A bit longer but readable and unambigous.

    Oren






More information about the Python-list mailing list