from datetime import datetime, timedelta from collections import defaultdict class ExpiringMap: def __init__(self): self.data = defaultdict(dict) def put(self, key, value, expire_time): current_time = datetime.now() expire_timestamp = current_time + timedelta(seconds=expire_time) self.data[key] = {'value': value, 'expire_time': expire_timestamp} def get(self, key): current_time = datetime.now() if key in self.data and self.data[key]['expire_time'] > current_time: return self.data[key]['value'] else: return None def remove(self, key): if key in self.data: del self.data[key]