Re: [Tutor] Output of list

2007-12-23 Thread Martin Walsh
János Juhász wrote: > Dear Marty, Hi Janos, >> ... Or, by extending Alan's solution ... >> >> def splitStringByN(s, n): >>for m in range(0, len(s), n): >>yield s[m:m+n] >> >> k = 'abcdefghi' >> list(splitStringByN(k, 2)) > > It seems to be the most readable solution for me. For comp

Re: [Tutor] Output of list

2007-12-23 Thread János Juhász
Dear Marty, >... Or, by extending Alan's solution ... > >def splitStringByN(s, n): >for m in range(0, len(s), n): >yield s[m:m+n] > >k = 'abcdefghi' >list(splitStringByN(k, 2)) It seems to be the most readable solution for me. >As it turns out, this is similar to an ASPN Cookbook r

Re: [Tutor] Output of list

2007-12-23 Thread Martin Walsh
János Juhász wrote: > It is nice place to use a generator: > > def pairs(sliceit): > streamlist = list(sliceit) > streamlist.reverse() > while streamlist: > pair = streamlist.pop() > try:pair += streamlist.pop() > except: pass > yield pair > > ##

Re: [Tutor] Output of list

2007-12-23 Thread János Juhász
Dear Emil, > I want to be capable of converting a string into a list where all > the items, in the list, have a fixed length not equal to 1 e.g i > have k = 'abcdefgh' and I want the fixed length for all the the > items to be 2 then the list would look like ['ab', 'cd', 'ef, 'gh']. > How do i

Re: [Tutor] Output of list

2007-12-22 Thread Ricardo Aráoz
Martin Walsh wrote: > Ricardo Aráoz wrote: >> Emil wrote: >>> hey >>> >>> I want to be capable of converting a string into a list where all the >>> items, in the list, have a fixed length not equal to 1 e.g i have k = >>> 'abcdefgh' and I want the fixed length for all the the items to be 2 then

Re: [Tutor] Output of list

2007-12-22 Thread Martin Walsh
Ricardo Aráoz wrote: > Emil wrote: >> hey >> >> I want to be capable of converting a string into a list where all the items, >> in the list, have a fixed length not equal to 1 e.g i have k = 'abcdefgh' >> and I want the fixed length for all the the items to be 2 then the list >> would look like

Re: [Tutor] Output of list

2007-12-22 Thread Alan Gauld
"Emil" <[EMAIL PROTECTED]> wrote > I want to be capable of converting a string into a list where all > the items, > in the list, have a fixed length not equal to 1 You can use list slicing to do this. Combine with the stepsize parameter of the range function > k = 'abcdefgh' and I want the f

Re: [Tutor] Output of list

2007-12-22 Thread Ricardo Aráoz
Emil wrote: > hey > > I want to be capable of converting a string into a list where all the items, > in the list, have a fixed length not equal to 1 e.g i have k = 'abcdefgh' > and I want the fixed length for all the the items to be 2 then the list would > look like ['ab', 'cd', 'ef, 'gh']. Ho

Re: [Tutor] Output of list

2007-12-22 Thread Ricardo Aráoz
Emil wrote: > hey > > I want to be capable of converting a string into a list where all the items, > in the list, have a fixed length not equal to 1 e.g i have k = 'abcdefgh' > and I want the fixed length for all the the items to be 2 then the list would > look like ['ab', 'cd', 'ef, 'gh']. Ho