Python | sympy.nC() method
With the help of sympy.nC() method, we can calculate the number of combinations of a given length in SymPy.
Syntax: nC(items, k)
Parameter:
items – An integer, a list or a string upon which combinations is to be calculated.
k – An integer specifying the length of the combinations.
Returns: Returns the number of combinations of a given length.
Example #1:
# import sympy from sympy import * items = "abca"k = 3print("Value of k = {} and the items are = {}".format(k, items)) # Use sympy.nC() method combinations = nC(items, k) print("Combinations : {}".format(combinations)) |
chevron_right
filter_none
Output:
Value of k = 3 and the items are = abca Combinations : 3
Example #2:
# import sympy from sympy import * items = [2, 1, 3, 5, 4] k = 3print("Value of k = {} and the items are = {}".format(k, items)) # Use sympy.nC() method combinations = nC(items, k) print("Combinations : {}".format(combinations)) |
chevron_right
filter_none
Output:
Value of k = 3 and the items are = [2, 1, 3, 5, 4] Combinations : 10
Recommended Posts:
- class method vs static method in Python
- Python | os.dup() method
- Python | set() method
- Python | next() method
- Python | os.scandir() method
- Python | cmath.log() method
- Python | os.ctermid() method
- Python | os.getppid() method
- Python | Tensorflow abs() method
- Python | cmath.exp() method
- Python | os.strerror() method
- Python | sys.getrecursionlimit() method
- Python | os.readv() method
- Python | Tensorflow log() method
- Python | os.writev() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



