不同列表之间的全排列

不同列表之间的全排列,适用于不同数据类型列表之间的组合

#coding='utf8'
board = {2: ['0', '1'], 3: ['0', '1', '2'], 4: ['0', '1', '2', '3'], 5: ['0', '1', '2', '3', '4'], 6: ['0', '1', '2', '3', '4', '5'], 7: ['0', '1', '2', '3', '4', '5', '6'], 8: ['0', '1', '2', '3', '4', '5', '6', '7'], 9: ['0', '1', '2', '3', '4', '5', '6', '7', '8'],10: ['0', '1', '2', '3', '4', '5', '6', '7', '8','9'],
        11: ['0', '1', '2', '3', '4', '5', '6', '7', '8','9','A'], 12: ['0', '1', '2', '3', '4', '5', '6', '7', '8','9','A','B'],13: ['0', '1', '2', '3', '4', '5', '6', '7', '8','9','A','B','C'],14: ['0', '1', '2', '3', '4', '5', '6', '7', '8','9','A','B','C','D'],15: ['0', '1', '2', '3', '4', '5', '6', '7', '8','9','A','B','C','D','E'],16: ['0', '1', '2', '3', '4', '5', '6', '7', '8','9','A','B','C','D','E','F']
         }
def combination(*args: list):
    config = [e for e in args]
    res = []
    tmp = []
    # 把整体的列表都放在config
    dfs(res, tmp, config, 0)
    return res

# dfs没变动
def dfs(res=[], tmp=[], config=[], i=0):
    if i == len(config):
        res.append(tmp.copy())
    else:
        for e in config[i]:
            # change spot
            tmp.append(e)
            # new condition,new recursion
            dfs(res, tmp, config, i + 1)
            # restore spot
            tmp.pop(len(tmp) - 1)

"""
combination用来对所有输入列表进行全排列
"""
a = [[1,2,3,4],['s','s','s','s'],[5,6,7,8,8],[1,2,3,4,5],[6,7,8,9]]
combination(*a)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值