我正在尝试在 Python 中创建一个函数,该函数将整数列表作为输入并返回一个更大的列表,其中包含这些数字的所有正负可能性。
假装“+”是正数,“-”是负数
输出应与:
foo([-4])
>>> [ [4], [-4] ]
foo([+, +])
>>> [ [+,+], [+,-], [-,+], [-,-] ]
foo([-, +])
>>> [ [+,+], [+,-], [-,+], [-,-] ]
foo([-1, 3])
>>> [ [1,3], [1,-3], [-1,3], [-1,-3] ]
foo( [+,-,+] )
>>> [ [-,-,-],[+,-,-],[-,+,-],[-,-,+],[+,+,-],[+,-,+],[-,+,+],[+,+,+] ]