Last active
August 29, 2015 14:04
-
-
Save kvbik/305f284cee31a2c2cbf3 to your computer and use it in GitHub Desktop.
co je na tom spatne?
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
In [1]: class O(object): | |
...: def _neco(self, param): | |
...: return param | |
...: def __init__(self, *args, **kwargs): | |
...: self.something = s = {} | |
...: for a,b in [(1,10),(2,20),(3,30)]: | |
...: s[a] = lambda: self._neco(b) | |
...: | |
In [2]: o = O() | |
In [3]: o.something[1]() | |
Out[3]: 30 |
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
functions = {} | |
def f(param): | |
return param | |
for a,b in [(1,10), (2,20), (3,30)]: | |
functions[a] = lambda: f(b) | |
# ocekval bych 10, ale dostanu 30 | |
print functions[1]() | |
# ocekval bych 10, ale dostanu 30 | |
print functions[2]() | |
# to je ta posledni lambda, takze dostanu 30 | |
print functions[3]() |
b = 17
print functions[1]() #hadej
b = 42
print functions[1]() #hadej znovu
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ani to nemusi byt objekt.. viz lambda2.py