Re: [Tutor] Splitting a string into n-sized bytes

2006-03-15 Thread Kent Johnson
Steve Nelson wrote: > Indeed - as I now have a function: > > def nsplit(s, n): > return [s[i:i+n] for i in range(0, len(s), n)] > > Incidentally I am currently going with: > > def nsplit(s, n): > while s: >yield s[:n] >s = s[n:] You can write the generator function to use the same m

Re: [Tutor] Splitting a string into n-sized bytes

2006-03-14 Thread Steve Nelson
On 3/14/06, Adam <[EMAIL PROTECTED]> wrote: > Hopefully that should point you in the right direction to do n-sized > words as well. Indeed - as I now have a function: def nsplit(s, n): return [s[i:i+n] for i in range(0, len(s), n)] Incidentally I am currently going with: def nsplit(s, n):

Re: [Tutor] Splitting a string into n-sized bytes

2006-03-14 Thread Smith
| From: "Steve Nelson" | | Further to my previous puzzling, I've been working out the best way to | chop a string up into n-sized words: | I think the follow use of groupby is from Raymond Hettinger from ASPN recipes. The batch() function will return an iterable to you in user-definable sized

Re: [Tutor] Splitting a string into n-sized bytes

2006-03-14 Thread Adam
On 14/03/06, Steve Nelson <[EMAIL PROTECTED]> wrote: > Hello all, > > Further to my previous puzzling, I've been working out the best way to > chop a string up into n-sized words: > > I'm aware that I can use a slice of the string, with, eg, myWord[0:4]. > > I am also aware that I can do blob = myW