Created
October 19, 2017 01:35
-
-
Save JadenGeller/7652a797139fd38b01c8eef4ee5c8ceb to your computer and use it in GitHub Desktop.
DynamicDict
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
#!/usr/bin/python | |
import string | |
class DynamicDict: | |
def __init__(self, function): | |
self._function = function | |
def __getitem__(self, key): | |
return self._function(key) | |
temp = string.Template("I think that $Jaden is $cool.") | |
print(temp.substitute(DynamicDict(lambda x: x + "ooo"))) | |
# -> I think that Jadenooo is coolooo. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment