Skip to content

Instantly share code, notes, and snippets.

@FuruNov
Created March 29, 2023 11:53
Show Gist options
  • Select an option

  • Save FuruNov/38844931e577c4227c212ccd17defe85 to your computer and use it in GitHub Desktop.

Select an option

Save FuruNov/38844931e577c4227c212ccd17defe85 to your computer and use it in GitHub Desktop.
関数の引数を入れ替える Python 関数
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