Re: Splitting a string into groups of three characters

2005-08-08 Thread John Machin
William Park wrote: > [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > >>Hi, >> >>Is there a function that split a string into groups, containing an "x" >>amount of characters? >> >>Ex. >>TheFunction("Hello World",3) >> >>Returns: >> >>['Hell','o W','orl','d'] >> >> >>Any reply would be truly apprec

Re: Splitting a string into groups of three characters

2005-08-08 Thread Gregory Piñero
I guess this question has already been thouroughly answered but here is my version: def split(string,n): outlist=[] for bottom in range(0,len(string),n): top=min(bottom+n,len(string)) outlist.append(string[bottom:top]) return outlist On 8/8/05, William Park <[EMAIL

Re: Splitting a string into groups of three characters

2005-08-08 Thread William Park
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Hi, > > Is there a function that split a string into groups, containing an "x" > amount of characters? > > Ex. > TheFunction("Hello World",3) > > Returns: > > ['Hell','o W','orl','d'] > > > Any reply would be truly appreciated. Look into 're' mo

Re: Splitting a string into groups of three characters

2005-08-08 Thread Cyril Bazin
Another solution derived from an old discussion about the same problem? def takeBy(s, n):     import itertools     list(''.join(x) for x in itertools.izip(*[iter(s)]*n)) (Hoping len(s) % n = 0) CyrilOn 8 Aug 2005 11:04:31 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED] > wrote:Yes i know i made a mi

Re: Splitting a string into groups of three characters

2005-08-08 Thread [EMAIL PROTECTED]
Yes i know i made a mistake, >['Hell','o W','orl','d'] but you know what I mean lol, I'll probly use John Machin's def nsplit(s, n): return [s[k:k+n] for k in xrange(0, len(s), n)] It seems fast, and does not require any imports. But anyways, thank you for all your help, you rock! :) --

Re: Splitting a string into groups of three characters

2005-08-08 Thread [EMAIL PROTECTED]
Yes i know i made a mistake, >['Hell','o W','orl','d'] but you know what I mean lol, I'll probly use John Machin's def nsplit(s, n): return [s[k:k+n] for k in xrange(0, len(s), n)] It seems fast, and does not require any imports. But anyways, thank you for all your help, you rpck! :) --

Re: Splitting a string into groups of three characters

2005-08-08 Thread Maksim Kasimov
import re str = '123456789983qw' re.findall("(.{3})", str)+[str[-(len(str) % 3):]] [EMAIL PROTECTED] wrote: > Hi, > > Is there a function that split a string into groups, containing an "x" > amount of characters? > > Ex. > TheFunction("Hello World",3) > > Returns: > > ['Hell','o W','orl','d']

Re: Splitting a string into groups of three characters

2005-08-07 Thread John Machin
gene tani wrote: > Um, you shd 1st search cookbook, or Vaults Parnassu, dmoz python > section, pypackage: > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/347689 which includes e.g. def each_slice_lol(listin,n): """non-overlapp'g slices, return (list of lists) """ len_listin=le

Re: Splitting a string into groups of three characters

2005-08-07 Thread Terry Reedy
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Is there a function that split a string into groups, containing an "x" > amount of characters? There have been previous threads giving various solutions (which generally are not specific to strings). You might find some some by sear

Re: Splitting a string into groups of three characters

2005-08-07 Thread [EMAIL PROTECTED]
Thank You, For your help, I guess I will just make a couple of these functions and find out which one is that fastest. -- http://mail.python.org/mailman/listinfo/python-list

Re: Splitting a string into groups of three characters

2005-08-07 Thread gene tani
Um, you shd 1st search cookbook, or Vaults Parnassu, dmoz python section, pypackage: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/347689 http://www.codezoo.com/ http://www.vex.net/parnassus/ http://www.pypackage.org/packages -- http://mail.python.org/mailman/listinfo/python-list

Re: Splitting a string into groups of three characters

2005-08-07 Thread John Machin
[EMAIL PROTECTED] wrote: > Hi, > > Is there a function that split a string into groups, containing an "x" > amount of characters? > > Ex. > TheFunction("Hello World",3) > > Returns: > > ['Hell','o W','orl','d'] > > > Any reply would be truly appreciated. > > Thank You, > Maybe, somewhere o

Splitting a string into groups of three characters

2005-08-07 Thread [EMAIL PROTECTED]
Hi, Is there a function that split a string into groups, containing an "x" amount of characters? Ex. TheFunction("Hello World",3) Returns: ['Hell','o W','orl','d'] Any reply would be truly appreciated. Thank You, -- http://mail.python.org/mailman/listinfo/python-list