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 PROTECTED]> 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 appreciated. > > Look into 're' module. Essentially, split using '...', but return the > separator as well. Then, remove empty items. In Bash shell, you would > do > a="Hello World" > set -- "${a|?...}" # extract '...' separators > pp_collapse # remove null items > printf '{%s}\n' "[EMAIL PROTECTED]" > > Translating to Python is left as homework. > > -- > William Park <[EMAIL PROTECTED] >, Toronto, Canada > ThinFlash: Linux thin-client on USB key (flash) drive > http://home.eol.ca/~parkw/thinflash.html > BashDiff: Super Bash shell > http://freshmeat.net/projects/bashdiff/ > -- > http://mail.python.org/mailman/listinfo/python-list > -- Gregory Piñero Chief Innovation Officer Blended Technologies (www.blendedtechnologies.com) -- http://mail.python.org/mailman/listinfo/python-list