2009/12/27 joy99 <subhakolkata1...@gmail.com>: > Dear Group, > Answers were good. But I am looking for a smarter solution like: > > for i[:2] in list: > .... > > etc. or by doing some looping over loop. > Do not worry I'll work out the answer. > > Wishing you a happy day ahead, > Regards, > Subhabrata. > -- > http://mail.python.org/mailman/listinfo/python-list > Hi, maybe just something like:
>>> input_list = range(10) >>> n = 3 >>> [input_list[i:i+n] for i in range(0, len(input_list), n)] [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]] >>> ? (possibly using xrange and generator expression instead of the list comprehension) vbr -- http://mail.python.org/mailman/listinfo/python-list