An adaptation to Hrvoje Niksic's recipe

Use a dictionary comprehention instead of a list comprehension or
function call:

lyst = [1, 2, 3, 4, 5, 6, 7, 'a', 8, 'b']

it = iter( lyst )
dyct = {i:it.next() for i in it}  # I'm using {} and not [] for those
with tiny fonts.

#print dyct
{8: 'b', 1: 2, 3: 4, 5: 6, 7: 'a'}

Of course check for an "even" number of elements to the original list
to avoid exceptions or dropping the last element on traps.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to