This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def add_item(item, items=None): | |
| if items is None: | |
| items = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Design an in-memory key–value store with TTL | |
| You are asked to implement a very simple in-memory key–value store for configuration data. | |
| The store supports four operations: | |
| set(key, value, ttl_seconds, now) | |
| get(key, now) | |
| delete(key, now) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class A: | |
| def say(self): | |
| print("A") | |
| class B(A): | |
| def say(self): | |
| print("B") | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class debug: | |
| def __init__(self, func): | |
| self.func = func | |
| def __get__(self, instance, owner): | |
| if instance is None: | |
| return self.func | |
| def wrapper(*args, **kwargs): | |
| print(f"Calling {self.func.__name__} of {instance!r}") |