Created
May 21, 2016 23:52
-
-
Save ambv/c6efa22e21de9b6b22147595cdc93d44 to your computer and use it in GitHub Desktop.
Requires Python 3.3+
This file contains 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
from contextlib import ExitStack | |
d = {index: str(index) for index in range(100)} | |
with ExitStack() as stack: | |
for key in d: | |
if key % 13 == 0: | |
stack.callback(d.pop, key) | |
print(d) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
IMHO simpler and good enough in most cases is: