def test_taxicab2(self): cases = { (1, 2, 3, 4): 4, (1, 2, 1, 2): 0, (2, 1, 4, 3): 4, } for case in cases: self.assertEqual(taxicab2(*case), cases[case])
def iteritemsnear(self, key, radius): """ A version of ``iteritems()`` that filters based on the distance from a given key. The key does not need to actually be in the dictionary. """ for coords in self.keys_near(key, radius): for target, value in self.buckets[coords].iteritems(): if taxicab2(target[0], target[1], key[0], key[1]) <= radius: yield target, value