I have a list if items/ tuples which contain sets like this:
a_list = [(a, {x}), (b, {y}), (c, {y,z}), (d, {y,z}), (e, {x,y}), (f, {x,y,z})]
And a sample pattern:
pattern = {x,y}
Given a number of draws i would like to generate a sequence of items from a_list that fits the pattern most. The pattern shall be fulfilled with the second part of the tuple, the set.
Example:
A result with draws = 2
could be:
result = [(a, {x}), (b, {y})]
# x, y
or
result = [(e, {x,y}), (a, {x})]
# x, y
or
result = [(e, {x,y}), (b, {y})]
# x, y
Both cases fulfill the pattern {x,y} within 2 draws.
A result with draws = 1
could only be:
result = (e, {x,y})
# x, y
since there is only one draw to fulfill the pattern and only item e matches the pattern totally.
A result with draws = 7
could be:
result = [(a, {x}), (b, {y}), (e, {x,y}), (f, {x,y,z}), (c, {y,z})]
# x, y, x, y, x, y, y
Can such a function be accomplished and if, how?
Thanks for your help!
Muffin