list 2 dictionary newcomer question
Remco Gerlich
scarblac at pino.selwerd.nl
Wed Jun 20 02:26:38 EDT 2001
Tom Messmer <t_messmer at yahoo.com> wrote in comp.lang.python:
> Lets say I have a list of arbitrary, but definitely even length, and I
> want to convert it to a dictionary. List might look like ['/', '15',
> '/proc', '100'](I'm parsing the output of df) I'd simply like to pair
> 'em up like {'/':'15', '/proc':'100'} I have a feeling I'm going to be
> embarrassed at how easy this is, but I cant seem to figure it out.
> I've seen examples on doing this with lists of lists, but not flat
> lists. Any takers?
L = [...]
dict = {}
for i in range(0, len(L), 2):
dict[L[i]] = L[I+1]
--
Remco Gerlich
More information about the Python-list
mailing list