Slicing Arrays in this way
Tobiah
toby at tobiah.org
Wed May 2 18:30:18 EDT 2007
John Machin wrote:
> 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]
I like it, and it fits my definition of elegant.
--
Posted via a free Usenet account from http://www.teranews.com
More information about the Python-list
mailing list