Python : updating values in a dictionary
I have the following dictionary ->
key : (time,edge_list)
Now I开发者_开发问答 want to increment all time values by 1. How do I do that?
dict_list = dict(key:(time+1,edge_list) for key:(time,edge_list) in dict_list)
>>> d={"key" : (100,"edge_list")}
>>> for i,(time,edge_list) in d.items():
... d[i] = time+1, edge_list
...
>>> d
{'key': (101, 'edge_list')}
dict((key, (time + 1, edge_list)) for (key, (time, edge_list)) in somedict.iteritems())
精彩评论