I feel stoopid ... this code is to verbose

Christophe Delord christophe.delord at free.fr
Fri Jun 14 13:05:35 EDT 2002


On Fri, 14 Jun 2002 18:49:08 +0200
Christophe Delord <christophe.delord at free.fr> wrote:

> 
> Here is a 3-liner ;-)
> 
> 
> > > I just cannot seem to find the nice 3-liner I expected from the 
> > > beginning. Has anybody got a better solution ? I thought somebody might 
> > > find it a fun exercise. Well I have...
> 
> def stringSlicer(st, chunkSize=3):
> 	def slc(st): return st and slc(st[:-chunkSize])+[st[-chunkSize:]] or []
> 	return ".".join(slc(st))
> 
> 
> 

Or maybe this 1-liner:

def stringSlicer(st, sz=3, d=''): return st and stringSlicer(st[:-sz],sz,'.')+st[-sz:]+d or ""




More information about the Python-list mailing list