Matimus wrote: > On May 2, 3:03 pm, Tobiah <[EMAIL PROTECTED]> wrote: >> >>> elegant_solution([1,2,3,4,5,6,7,8,9,10]) >> [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]] >> >> -- >> Posted via a free Usenet account fromhttp://www.teranews.com > >>>> seq = range(1,11) >>>> seq > [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>>> zip( seq[0::2],seq[1::2] ) > [(1, 2), (3, 4), (5, 6), (7, 8), (9, 10)] > > if you _really_ need lists then... >>>> map(list, zip( seq[0::2],seq[1::2] )) > [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]] >
I had come up with: [[a[x], a[x + 1]] for x in range(0, 10, 2)] I was hoping for something a little more concise. Something like list[::2:2] if that existed. -- Posted via a free Usenet account from http://www.teranews.com -- http://mail.python.org/mailman/listinfo/python-list