#!/usr/bin/env python class lindict (dict): def __init__ (self, **kwargs): dict.__init__ (self, **kwargs) self.default = 0.0 def __getitem__ (self, key): try: return dict.__getitem__ (self, key) except KeyError: less = [x for x in self.keys() if x < key] more = [x for x in self.keys() if x > key] if less and more: less = max (less) more = min (more) key = float (key - less) / (more - less) return (1 - key) * self[less] + key * self[more] else: return self.default if __name__=='__main__': ld = lindict () ld[5] = 20 ld[10] = 5 ld[15] = 10 for i in range (0, 20): print ld[i]