Python: updating values ​​in a dictionary

I have the following dictionary →

key : (time,edge_list)

Now I want to increase all the time values ​​by 1. How to do this?

dict_list = dict(key:(time+1,edge_list) for key:(time,edge_list) in dict_list)
+3
source share
2 answers
>>> d={"key" : (100,"edge_list")}
>>> for i,(time,edge_list) in d.items():
...  d[i] = time+1, edge_list
... 
>>> d
{'key': (101, 'edge_list')}
+9
source
dict((key, (time + 1, edge_list)) for (key, (time, edge_list)) in somedict.iteritems())
+7
source

Source: https://habr.com/ru/post/1733314/


All Articles