On Thu, Oct 21, 2004 at 02:43:12PM +1300, Carl Cerecke wrote:
I have a list with an even number of elements, and I want to step through each pair of elements.
So, for example, with the list ls=[1,2,3,4,5,6], I want to deal with 1,2 then 3,4 then 5,6.
this is not a python solution, but an excellent opportunity to show some of the nicer features of pike:
array ls=({ 1,2,3,4,5,6 }); array pairs=ls/2;
the result is then: ({ ({ 1,2 }), ({ 3,4 }), ({ 5,6 }) })
List division! Very convenient feature. You can get list division in python by subclassing list and defining the __div__ method (if you really wanted to)
What is the story with those ({ and }) delimiters? They're quite syntactically ugly, IMO. And possibly a lot of potential for getting the pike parser thoroughly confused if you get them around the wrong way.
Cheers, Carl.
