Dictionary from a list

Jan Kaliszewski zuo at chopin.edu.pl
Thu Aug 20 02:29:32 CEST 2009


20-08-2009 o 02:05:57 Jan Kaliszewski <zuo at chopin.edu.pl> wrote:

> Or probably better:
>
>      from itertools import islice, izip
>      dict(izip(islice(li, 0, None, 2), islice(li, 1, None, 2)))

Or similarly, perhaps more readable:

     iterator = iter(li)
     dict((iterator.next(), iterator.next()) for i in xrange(len(li)/2))

-- 
Jan Kaliszewski (zuo) <zuo at chopin.edu.pl>



More information about the Python-list mailing list