I want something equivalent to the following code. The following code generate poker possible hand patterns.
from itertools import combinations
m = 13
n = 4
x = range(m) * n
y = 5
pattern = set()
for i in combinations(x, y):
pattern.add(tuple(sorted(i)))
I tried to use itertools.combinations_with_replacement
. Not surprisingly there are combinations like (0, 0, 0, 0, 0) or (1, 1, 1, 1, 1). But there are no 5 Queens and 5 Kings in a cards. So I don't want to take 5 same things. How do I implement restricted combinations iterator.
from itertools import combinations_with_replacement
m = 13
n = 4
x = range(m)
y = 5
pattern = []
for i in combinations_with_replacement(x, y):
pattern.append(i)
I want like the following code.
Pseudo code:
m = 13
n = 4
x = range(m)
y = 5
pattern = []
for i in combinations_with_replacement_restricted(x, y, max=n):
pattern.append(i)
P.S. Because I'm English learner, please modify my grammar mistakes.