How to split string in equally long parts

Mike Rovner mike at bindkey.com
Tue Apr 8 17:11:14 EDT 2003


def split(S,N):
  """S - source string
     N - number of parts
  """
  lens=len(s)
  l=lens/N
  return [S[i:i+l] for i in xrange(0,lens,l)]

Mike

PS. Task description is too vague.

"Heiko Henkelmann" <heiko at hhenkelmann.de> wrote in message
news:b6vd0e$i1b$01$1 at news.t-online.com...
> I need to split a string into an array of equally long substrings, like
> e.g.:
>
> '1234567890'   -> ['12', '34','56','78','90']
>
> What is the most efficient way to do this?
>
> Heiko








More information about the Python-list mailing list