On Tue, 22 Nov 2005 13:37:06 +0100, =?ISO-8859-1?Q?Andr=E9?= Malo <[EMAIL 
PROTECTED]> wrote:

>* Duncan Booth <[EMAIL PROTECTED]> wrote:
>
>> metiu uitem wrote:
>> 
>> > Say you have a flat list:
>> > ['a', 1, 'b', 2, 'c', 3]
>> > 
>> > How do you efficiently get
>> > [['a', 1], ['b', 2], ['c', 3]]
>> 
>> That's funny, I thought your subject line said 'list of tuples'. I'll 
>> answer the question in the subject rather than the question in the body:
>> 
>> >>> aList = ['a', 1, 'b', 2, 'c', 3]
>> >>> it = iter(aList)
>> >>> zip(it, it)
>> [('a', 1), ('b', 2), ('c', 3)]
>
>Though it looks nice, it's an implementation dependant solution. What if
>someone changes zip to fetch the second item first?
>
That would be a counter-intuitive thing to do. Most things go left->right
in order as the default assumption.

Regards,
Bengt Richter
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to