Created
April 17, 2017 23:20
-
-
Save nasturtus/a087c202760d1dba5da2214ef26906da to your computer and use it in GitHub Desktop.
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
# Illustrating idemptotence | |
# An operation is idempotent if f(x) => n, f(f(x)) => n, f(f(f(x))) => n .. | |
# Reference: | |
# Corey Schafer https://www.youtube.com/watch?v=UaKZ4wKytcA | |
# The following is not idempotent since the results from square(n) | |
# and square(square(n)) differ. | |
def square(n): | |
return n * n | |
print(square(10)) | |
print(square(square(10))) | |
# The following is idempotent. | |
print(abs(-100)) | |
print(abs(abs(-100))) | |
print(abs(abs(abs(-100)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment