I am looking for an elegant(fast) python function that produces every combination from the following two arrays.
cards = ["8H", "8S", "8C", "8D", "9H", "9S", "9C", "9D", "10H", "10S", "10C", "10D", "AH", "AS", "AC", "AD"]
players = ["_1", "_1", "_1", "_2", "_2", "_2", "_3", "_3", "_3", "_4", "_4", "_4", "_To", "_To", "_To", "_Tc"]
A combination would look like:
[('8H', '_1'), ('8S', '_1'), ('8C', '_1'), ('8D', '_2'), ('9H', '_2'), ('9S', '_2'), ('9C', '_3'), ('9D', '_3'), ('10H', '_3'), ('10S', '_4'), ('10C', '_4'), ('10D', '_4'), ('AH', '_To'), ('AS', '_To'), ('AC', '_To'), ('AD', '_Tc')]
But! without equals, what I mean with that. Example:
If cards would be:
["a", "b", "c", "d"]
If players would be:
["1", "1", "2", "2"]
Result:
[1a, 1b, 2c, 2d]
[1a, 1c, 2b, 2d]
[1a, 1d, 2b, 2c]
[1b, 1c, 2a, 2d]
[1b, 1d, 2a, 2c]
[1c, 1d, 2a, 2b]
Not for example:
[1a, 1b, 2d, 2c]
Player 2 having (c and d) is equal to (d and c)
I have tried a function of itertools
, like combinations
and permutations
but without luck. Rejecting equals after having all combinations is not really an option, because of the state space explosion.
I hope someone has a solution, because google search for this specific problem failed.