Re: Transforming a List of elements into a List of lists of elements

2010-01-08 Thread Jan Kaliszewski
PS. Sorry, I wrote: >>> zip(*[iter(s)]*3) # or simpler: zip(s) :-) But should be >>> zip(*[iter(s)]*1) # or simpler: zip(s) :-) *j -- http://mail.python.org/mailman/listinfo/python-list

Re: Transforming a List of elements into a List of lists of elements

2010-01-08 Thread Jean-Michel Pichavant
tiago almeida wrote: Hello all, I'd like to ask how you'd implement a function /f/ that transforms a list of elements into a list of lists of elements by grouping contiguous elements together. Examples: a=[1,2,3,4,5] print( f(a, 2) ) # -> [ [1, 2], [3, 4], [5] ] print( f(a, 3) ) # -> [ [

Re: Transforming a List of elements into a List of lists of elements

2010-01-08 Thread Jan Kaliszewski
08-01-2010 tiago almeida wrote: Hello all, I'd like to ask how you'd implement a function *f* that transforms a list of elements into a list of lists of elements by grouping contiguous elements together. Examples: a=[1,2,3,4,5] print( f(a, 2) ) # -> [ [1, 2], [3, 4], [5] ] print( f(a, 3)