Adding a constant integer to a value in a python dictionary

前端 未结 3 1900
陌清茗
陌清茗 2021-01-15 17:55

How would you add a constant number, say 1, to a value in a dictionary if certain conditions are fulfilled.

For example, if I had a dictionary:

dict          


        
3条回答
  •  时光取名叫无心
    2021-01-15 18:32

    Your code says the following:

    for each value in [3,3,4,4,4]:
        if 1 < value < 5:
            FID_thingy['0'] = value + 1
    

    So it will set FID_thingy['0'] to 4 then 4 then 5 then 5 then 5. Do you see why?

提交回复
热议问题