Dictionary from a list

Steven D'Aprano steven at REMOVE.THIS.cybersource.com.au
Thu Aug 20 03:05:41 EDT 2009


On Thu, 20 Aug 2009 08:10:28 +0200, Peter Otten wrote:


> I just can't stop posting this one:
> 
>>>> from itertools import izip
>>>> it = iter([1,2,3,4,5,6])
>>>> dict(izip(it, it))
> {1: 2, 3: 4, 5: 6}
> 
> I really tried, but yours drove me over the edge.

If you want something to drive you over the edge:


>>> alist = [1, 2, 3, 4, 5, 6]
>>> dict(apply(zip, map(lambda n: map(lambda t: t[1], filter(lambda t: 
((not (t[0]%2)) == 1) == n, enumerate(alist))), range(1, -1, -1))))
{1: 2, 3: 4, 5: 6}


Enjoy :)



-- 
Steven



More information about the Python-list mailing list