Converting a flat list to a list of tuples

Dave Hansen iddw at hotmail.com
Tue Nov 22 21:55:28 CET 2005


On Tue, 22 Nov 2005 20:12:52 GMT in comp.lang.python, bokr at oz.net
(Bengt Richter) wrote:

>On Tue, 22 Nov 2005 13:26:45 +0100, "Fredrik Lundh" <fredrik at pythonware.com> wrote:
>
>>Duncan Booth wrote:
>>
>>> 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)]
>>
[...]
>
>Hm, actually, something tells me I've seen some variation of this before,
>but I can't think of the context off hand.

Earlier this fall I posted a question about iterating over a sequence
while modifying it.  Google should bring it up.

This strikes me as the same idea, only inside-out...

Regards,
                                        -=Dave

-- 
Change is inevitable, progress is not.



More information about the Python-list mailing list