Bringing it all together, thanks to this answer, you should be able to achieve your result like this:
import itertools
# Inputs
deck = [[7, 'Cups'], [2, 'Cups'], ['K', 'Swords'], ['Q', 'Clubs'], ['K', 'Cups'], [10, 'Clubs'], [9, 'Clubs'], [1, 'Swords']]
card = [10, 'Coins']
# Replace figures
mapping = {'J': 11, 'Q': 12, 'K': 13}
deck = [[mapping.get(cc[0], cc[0]), cc[1]] for cc in deck]
# Fill target
target = card[0]
result = [seq for i in range(len(deck), 0, -1)
for seq in itertools.combinations(deck, i)
if sum(s[0] for s in seq) == target]
print(result)
# prints [([7, 'Cups'], [2, 'Cups'], [1, 'Swords']), ([9, 'Clubs'], [1, 'Swords']), ([10, 'Clubs'],)]
- J, Q, and K are mapped to numbers (you may map them back if you wish).
- Your
target
is the value of card
, while you do not need numbers
since you want to keep the suits too.
- You should just update the list comprehension for your
result
by ensuring you are checking the values only -> thus, sum(seq)
becomes sum(s[0] for s in seq)
since each seq
is a value-suit pair now.