"Variable variable name" or "variable lvalue"

Roberto Bonvallet rbonvall at gmail.com
Tue Sep 11 23:08:48 EDT 2007


On Aug 15, 4:19 pm, Peter Otten <__pete... at web.de> wrote:
> If you want to simplify things somewhat you can merge the two loops into
> one:
>
>     numbers = [12.5, 25, 12.5]
>     accu = Material(numbers[0])
>     for x in numbers[1:]:
>         accu += Material(x)
>     period = Slab(accu)

Better to use the `sum' builtin and a generator expression:

    period = Slab(sum(Material(x)) for x in numbers)

--
Roberto Bonvallet




More information about the Python-list mailing list