Last active
March 25, 2023 10:27
-
-
Save FuruNov/6a1f4010ee43922f19eef3ff856de10b to your computer and use it in GitHub Desktop.
関数の引数を逆順にして新しい関数を作成する関数
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
| import functools | |
| def flip(func): | |
| @functools.wraps(func) | |
| def wrapper(*args, **kwargs): | |
| new_args = args[::-1] | |
| return func(*new_args, **kwargs) | |
| return wrapper | |
| def sub(a, b): | |
| return a - b | |
| result = flip(sub)(2, 3) | |
| print(result) # 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment