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)

Cyril

On 8 Aug 2005 11:04:31 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED] > wrote:
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! :)

--
http://mail.python.org/mailman/listinfo/python-list

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to