how to extract an implicit dict expression (with statement return)
benjamin.kaplan at case.edu
Thu Sep 9 17:28:05 CEST 2010
On Thu, Sep 9, 2010 at 11:20 AM, Fritz Loseries <fritz at loseries.info> wrote:
> I do not know how to subject my problem in a better way.
> I have the following statement:
> return [ dict(x1 = elem.x1, x2 = elem.x2, x3 = elem.x3,)
> for elem in method(in_values)
> How can I transform it to an explicit description:
> result = ...
> return result
> Could not found a description for the here used form of for and what
> [...] means.
> Need this for debugging.
> Thanks for any help.
[ ] defines a list literal
[1, 2, 3]
This particular syntax [ ____ for ___ in ___] is a list comprehension.
It's creating an inline for-loop to generate a list. You can just lift
the whole expression for the assignment.
result = [ dict(x1 = elem.x1, x2 = elem.x2, x3 = elem.x3,)
for elem in method(in_values)
More information about the Python-list