Skip to content

Instantly share code, notes, and snippets.

@hanepjiv
Last active Aug 29, 2015
Embed
What would you like to do?
# coding: utf-8
# http://hanepjiv.blogspot.jp/2014/11/python-indentchoice.html
from functools import wraps
# ================================================
def choice(a_Func):
# --------------------------------------------------------------------------
def loop(*args):
if len(args) is 0:
return []
if len(args[1:]) is 0:
return [[i] for i in args[0]]
return [[i] + j for i in args[0] for j in loop(*args[1:])]
# --------------------------------------------------------------------------
@wraps(a_Func)
def wrapper(*args):
return [i for i in map((lambda args: a_Func(*args)), loop(*args))]
return wrapper
@choice
def hoge(*args):
return tuple(args)
print(hoge((0,), (1,2), (3,4,5), (6,7,8,9)))
@choice
def fuga(*args):
return sum(args)
print(fuga((0,), (1,2), (3,4,5), (6,7,8,9)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment