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
Post a Comment