Last active
August 29, 2015 14:15
-
-
Save msamoylov/07026636872c93331400 to your computer and use it in GitHub Desktop.
Python screening questions
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 powers(): | |
return [lambda x : x ** i for i in range(3)] | |
print [m(5) for m in powers()] # Produces [25, 25, 25] | |
# What would you change to get the expected [1, 5, 25] results? | |
def powers(): | |
for i in range(3): yield lambda x : x ** i | |
print [m(5) for m in powers()] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment