[omaha] expand my understanding...

Steve Young wereapwhatwesow at gmail.com
Sun Dec 12 00:19:42 CET 2010

I am going thru a book on testing, and ran across the following code:

class multiply:
    def __init__(self, *operands):
        self.operands = operands

    def evaluate(self, bindings):
        vals = [x.evaluate(bindings) for x in self.operands]

        if len(vals) < 2:
            raise ValueError('multiply without at least two '
                             'operands is meaningless')

        result = 1.0
        for val in vals:
            result *= val

        return result

The line "        vals = [x.evaluate(bindings) for x in self.operands]"
appears to take operand(s) and put them into a list.  I can't get my brain
to understand it. operands are any number of floating point numbers.  Any
tips greatly appreciated.

Steve Young

More information about the Omaha mailing list