Slicing Arrays in this way
John Machin
sjmachin at lexicon.net
Wed May 2 18:26:32 EDT 2007
On May 3, 8:03 am, Tobiah <t... at tobiah.org> wrote:
> >>> elegant_solution([1,2,3,4,5,6,7,8,9,10])
> [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]
>
What is your definition of "elegant"? What about other dimensions of
code quality like "robust" and "fast"?
What have you tried?
Here's one possibility:
zip(source[::2], source[1::2])
[I'm presuming you won't be upset by getting tuples instead of lists]
More information about the Python-list
mailing list