[omaha] expand my understanding...

Jeff Hinrichs - DM&T jeffh at dundeemt.com
Sun Dec 12 05:38:16 CET 2010


You are correct. It's a list  comprehension.
L=[1,2,3]
print [str(x) for x in L]

Prints out
['1', '2','3']

Jeff
 On Dec 11, 2010 5:19 PM, "Steve Young" <wereapwhatwesow at gmail.com> wrote:
> 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
> _______________________________________________
> Omaha Python Users Group mailing list
> Omaha at python.org
> http://mail.python.org/mailman/listinfo/omaha
> http://www.OmahaPython.org


More information about the Omaha mailing list