Last active
May 25, 2024 13:35
-
-
Save theSamyak/eb00e8b7331964c764de0b7248d27419 to your computer and use it in GitHub Desktop.
[FCC First class functions and Closures Blog] Passing Functions as Arguments
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
def double(n): | |
return n * 2 | |
def map_function(func, values): | |
result = [] | |
for value in values: | |
result.append(func(value)) | |
return result | |
# Use the custom map function | |
doubled_values = map_function(double, [3, 6, 9, 12, 15]) | |
print(doubled_values) # Output: [6, 12, 18, 24, 30] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment