【发布时间】:2014-08-09 23:15:41
【问题描述】:
我有一个由 N 个整数值组成的字典,如下所示:
units = {'trooper':2, 'tank':10, 'helicopter':12}
而且我还有一个目标值……比如 120。
我正在尝试找出方程式的所有可能结果:
a*units['trooper'] + b*units['tank'] + c*units['helicopter'] = 120
所以结果看起来像:
60*trooper
55*trooper + 1*tank
54*trooper + 1*helicopter
依此类推,字典中 N 个键的所有可能组合...
我该如何构建这个?
【问题讨论】:
标签: python dictionary combinations reduce