def test(): assert general_product((1, 2, 3)) == 6 assert general_product((1, 2, 3, 4)) == 24 assert general_product( ((0, 1), 2, 3)) == (0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1) assert general_product( (2, 3), start=(0, 1)) == (0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1)
def test(): assert general_product((1, 2, 3)) == 6 assert general_product((1, 2, 3, 4)) == 24 assert general_product(((0, 1), 2, 3)) == (0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1) assert general_product((2, 3), start=(0, 1)) == (0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1)
def __pow__(self, exponent): '''Raise the perm by the power of `exponent`.''' assert isinstance(exponent, numbers.Integral) if exponent <= -1: return self.inverse ** (- exponent) elif exponent == 0: return self.nominal_perm_space[0] else: assert exponent >= 1 return misc_tools.general_product((self,) * exponent)
def __pow__(self, exponent): '''Raise the perm by the power of `exponent`.''' assert isinstance(exponent, numbers.Integral) if exponent <= -1: return self.inverse**(-exponent) elif exponent == 0: return self.nominal_perm_space[0] else: assert exponent >= 1 return misc_tools.general_product((self, ) * exponent)
def factorial(x, start=1): ''' Calculate a factorial. This differs from the built-in `math.factorial` in that it allows a `start` argument. If one is given, the function returns `(x!)/(start!)`. Examples: >>> factorial(5) 120 >>> factorial(5, 3) 60 ''' from python_toolbox import misc_tools return misc_tools.general_product(range(start, x+1), start=1)
def product(numbers): '''Get the product of all the numbers in `numbers`.''' from python_toolbox import misc_tools return misc_tools.general_product(numbers, start=1)