Limiting the number of combinations in Python code

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