python - Inverse order of dictionary values -
i have python dictionary following:
mydict = {'cb_rdbu_4': [['202', '0', '32'], ['244', '165', '130'], ['146', '197', '222'], ['5', '113', '176']]}
i inverse order of elements in list. instance first key value list have following order:
'cb_rdbu_4': [['5', '113', '176'], ['146', '197', '222'], ['244', '165', '130'], ['202', '0', '32']]
how do that?
new_dict = dict([(key,reversed(value)) key,value in mydict.items()])
or if want edit in place
for key in mydict: mydict[key] = reversed(mydict[key])
instead of reversed(value)
can value[::-1]
Comments
Post a Comment