+ 1
how to check if a key is in between two another keys in a dictionary?
dict = {1:5, 5:6, 7:6, 9:8} if i have a task that if i get two integer let's say [4,8] i need to check that it is smaller to which keys in dict..keys() and need to insert a value(let's say '1') with key 4 and 8..and update or add the values of key 5 and 7(in b/w 4 and 8) by the new value...but for key 8, i need to insert a key value pair for that.. so i need a dict = {1:5, 5:7, 7:7, 8:1, 9:8} i am unable to check where the new key is smaller or greater than which of the keys which are already in the dict. help me to understand this, and share a code if you can..
2 Answers
+ 4
I still have not fully understand what and how you will modify the dict. May be you can make your sample easier to understand. May be you can tell us a bit more what the keys and values are used for. Thanks!
Some thoughts about 'inserting' new key-value pairs in the dict. You can not select the position where the new values should be placed, but after using dict.update(new_values) and a following sort, your new key will be at the desired place.
0
What?? Jay Matthews