In article <[email protected]>, Francesco Bochicchio <[email protected]> wrote: >> On Sat, Apr 11, 2009 at 1:44 AM, Matteo <[email protected]> wrote: >>> >>> I need to pass the numbers to a function, but three at a time, until >>> the string ends. The strings are of variable length, but always a >>> multiple of three. > >I would do that with a generator: > > >>> def groups(l,n) : >... while l: yield l[:n]; l=l[n:] >...
Unfortunately, that's O(N**2) albeit with an extremely small constant factor, because popping off the head of the list requires a full list copy. You're probably okay with this algorithm unless the string could be megabytes. -- Aahz ([email protected]) <*> http://www.pythoncraft.com/ Why is this newsgroup different from all other newsgroups? -- http://mail.python.org/mailman/listinfo/python-list
