python - Add Values to Existing Entry in Dictionary -


i starting out list

lists = [['test', '1', '-1', '0', '-1'],['test2', '0', '1', '0', '-1'] 

what want end {'test': [1, -1, 0, -1], 'test2': [0, 1, 0, -1]}

so basically, need create dictionary out of lists. values of dictionary need integers , not strings.

this non-working code:

endresult = dict() x in lists:     y in x:         endresult.update({x[0]:int(y)}) 

endresult = {} x in lists:     endresult[x[0]] = [int(y) y in x[1:]] 

example:

>>> lists = [['test', '1', '-1', '0', '-1'],['test2', '0', '1', '0', '-1']] >>> endresult = {} >>> x in lists: ...     endresult[x[0]] = [int(y) y in x[1:]] ... >>> endresult {'test2': [0, 1, 0, -1], 'test': [1, -1, 0, -1]} 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -