def memorized_timedelta(seconds):
 try:
  return _timedelta_cache[seconds]
 except KeyError:
  delta = timedelta(seconds=seconds)
  _timedelta_cache[seconds] = delta
  return delta

def memorized_timedelta ( seconds ) : try : return _timedelta_cache [ seconds ] except KeyError : delta = timedelta ( seconds = seconds ) _timedelta_cache [ seconds ] = delta return delta
create only one instance of each distinct timedelta .