Dictionary from a list

Peter Otten __peter__ at web.de
Thu Aug 20 03:45:37 EDT 2009


Steven D'Aprano wrote:

> 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:

I meant that figuratively...

>>>> 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}

...originally.

> Enjoy :)

Not ;)




More information about the Python-list mailing list