list 2 dict?

DevPlayer devplayer at gmail.com
Tue Jan 4 04:12:32 EST 2011


or only convert the item when you need it leaving the lists as the
source

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

func = lambda alist, index: dict([(lyst[index*2],
lyst[(index*2)+1]),])

func(lyst, 0)
{1: 2}

func(lyst, 2)
{5: 6}

##########------------
or as a function
def func(lyst, index):
    return dict(((lyst[index], lyst[index+1]),))



More information about the Python-list mailing list