I have a dictionary which has coordinate pairs as a keys: i.e.:
d = {(15,21): "value1", (7,45): "value2", (500,321): "value3",...}
Now I need to return a sub dictionary of the elements where the keys are within a certain range:
for example: the range of (6:16, 20:46) should return the following dictionary:
d = {(15,21): "Value1", (7,45): value2} if there was no other element in that range.
Is there any predefined dictionary function to do that? ..or do you have any other suggestions?
Thx
Here is one way to do it
Python 2.7 has added dictionary comprehensions. The last line becomes more readable: