Time:09-30
from itertools import chain, combinations L=[1, 2, 3, 4, 5] A=6 For c in print ([c chain (* (combinations (l, I) for I in range (1, len (l) + 1))) if the sum (c)==s]) Results: [(6), (1, 5), (2, 4), (1, 2, 3)]
CodePudding user response:
The from itertools import chain combinations L=[6] S=6 Cb=[] For I in range (1, len (l) + 1) : Cb. Append (combinations (l, I)) For c in chain (* cb) : If the sum (c)==s: Print (c)
Page link:https//www.codepudding.com/other/43662.html