add: add repr method

This commit is contained in:
mau
2026-06-19 17:56:27 +02:00
parent ef094795e6
commit 3c72af8ff6
+7 -1
View File
@@ -4,6 +4,9 @@ class LRUCache:
self.capacity = capacity
self.slots = []
def __repr__(self):
return ", ".join(map(lambda x: str(x), self.slots))
def get(self, key: int) -> int:
if key <= len(self.slots) -1:
return self.slots[key]
@@ -21,7 +24,10 @@ def main():
print(cache.get(0))
cache.put(0,1)
print(cache.get(0))
print(cache)
cache.put(1,2)
print(cache)
if __name__ == "__main__":
main()