Con la ayuda del método sympy.nC() , podemos calcular el número de combinaciones de una longitud determinada en SymPy.
Sintaxis: nC(elementos, k)
Parámetro:
elementos: un número entero, una lista o una string sobre la que se calcularán las combinaciones.
k: un número entero que especifica la longitud de las combinaciones.Devoluciones: Devuelve el número de combinaciones de una longitud dada.
Ejemplo 1:
# import sympy from sympy import * items = "abca" k = 3 print("Value of k = {} and the items are = {}".format(k, items)) # Use sympy.nC() method combinations = nC(items, k) print("Combinations : {}".format(combinations))
Producción:
Value of k = 3 and the items are = abca Combinations : 3
Ejemplo #2:
# import sympy from sympy import * items = [2, 1, 3, 5, 4] k = 3 print("Value of k = {} and the items are = {}".format(k, items)) # Use sympy.nC() method combinations = nC(items, k) print("Combinations : {}".format(combinations))
Producción:
Value of k = 3 and the items are = [2, 1, 3, 5, 4] Combinations : 10
Publicación traducida automáticamente
Artículo escrito por rupesh_rao y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA