Limiting the number of combinations in Python code

Letters are like there are 33 ones, 33 twos and 66 zeros amounting to total letters 132. If I do it manually, there will be a lot of combinations. To make it easy, I want to limit my iterations to 1000. Plz suggest the code.
my_letters=[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2]

1 Like

https://docs.python.org/3/library/itertools.html#itertools.combinations

Example:

from itertools import combinations
letters = [1, 1, 1, 2, 2, 0]
for count, combo in enumerate(combinations(letters, 3)):
    if count >= 5: break
    print(combo)

which gives:

(1, 1, 1)
(1, 1, 2)
(1, 1, 2)
(1, 1, 0)
(1, 1, 2)

Note: This thread is closely related to Limiting the number of combinations in Python.