Created
March 29, 2023 11:53
-
-
Save FuruNov/38844931e577c4227c212ccd17defe85 to your computer and use it in GitHub Desktop.
関数の引数を入れ替える Python 関数
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) # 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment