Skip to content

Instantly share code, notes, and snippets.

@FuruNov
Last active March 25, 2023 10:27
Show Gist options
  • Select an option

  • Save FuruNov/6a1f4010ee43922f19eef3ff856de10b to your computer and use it in GitHub Desktop.

Select an option

Save FuruNov/6a1f4010ee43922f19eef3ff856de10b to your computer and use it in GitHub Desktop.
関数の引数を逆順にして新しい関数を作成する関数
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