# Calculating and putting all possibilities of 36 ncr 10 in a list in python

Calculating and putting all possibilities of 36 ncr 10 in a list in Python can be achieved in different ways. In this article, we will explore three different approaches to solve this problem.

## Approach 1: Using the math module

``````import math

def calculate_ncr(n, r):
return math.comb(n, r)

n = 36
r = 10

possibilities = [calculate_ncr(n, i) for i in range(r+1)]
print(possibilities)``````

In this approach, we utilize the `math.comb()` function from the math module to calculate the combination. We iterate over the range of values from 0 to `r` (inclusive) and calculate the combination for each value. The results are stored in the `possibilities` list.

## Approach 2: Using a recursive function

``````def calculate_ncr(n, r):
if r == 0 or r == n:
return 1
else:
return calculate_ncr(n-1, r-1) + calculate_ncr(n-1, r)

n = 36
r = 10

possibilities = [calculate_ncr(n, i) for i in range(r+1)]
print(possibilities)``````

In this approach, we define a recursive function `calculate_ncr()` that calculates the combination using the formula `nCr = (n-1)C(r-1) + (n-1)Cr`. We start with the base cases where `r` is 0 or equal to `n`, which returns 1. For other values, we recursively call the function with reduced values of `n` and `r`. The results are stored in the `possibilities` list.

## Approach 3: Using the itertools module

``````import itertools

n = 36
r = 10

possibilities = list(itertools.combinations(range(n), r))
print(possibilities)``````

In this approach, we utilize the `combinations()` function from the itertools module to generate all possible combinations of length `r` from the range of values from 0 to `n-1`. The results are stored in the `possibilities` list.

After evaluating all three approaches, it can be concluded that Approach 1 using the math module is the most efficient and straightforward solution for calculating and putting all possibilities of 36 ncr 10 in a list in Python. It provides a built-in function specifically designed for calculating combinations, resulting in cleaner and more readable code.

Rate this post

### 11 Responses

1. Alexandria says:

Approach 3 with itertools module is like a magician revealing tricks! Mind-blowing efficiency! 🎩🔥

2. Dante says:

Approach 3 seems like the way to go! Who doesnt love itertools? 🐍

3. Santino says:

Approach 2 seems like a fun challenge, but Id go with Approach 3 for simplicity. Thoughts?

4. Bear says:

Approach 3 with itertools seems like a ninja move! Love the elegance and simplicity. 🥷💯

5. Azriel Correa says:

Approach 2 seems like a fun challenge, but Approach 3 sounds more efficient. What do you guys think? 🤔

1. Leonardo says:

I personally believe that Approach 2 is the way to go. It adds an element of excitement and creativity to the challenge. Who needs efficiency when you can have fun? But hey, thats just my opinion. Lets hear what others have to say! 😄

6. Beau Hardy says:

Approach 2 sounds like a fun challenge, but Im curious if its more efficient than Approach 1.

7. Yareli Howe says:

Approach 2 sounds cool, but I wonder if its more efficient than the others. Any thoughts?

1. Aila Stevens says:

Ive tried approach 2 and found it to be incredibly efficient. It streamlined my workflow like nothing else. Give it a shot and see for yourself!

8. Theodore Trevino says:

Approach 1 seems simple, but approach 3 with itertools module sounds intriguing! #PythonMath

9. Myla Ayala says:

Approach 2 seems like a mind-bending challenge! Recursive functions always make my brain go zigzag.