I'm not too familiar with Python so forgive me if these two things are unrelated.
I'm working with an ORM for the first time (SQLALCHEMY) and it's interesting but quite confusing. Today I ran into a weird issue and I'm pretty puzzled but hoping someone can clear it up for me. Essentially I want to know what the difference between this:
[[x.item for x in y.items] for y in yy]
and this:
[x.item for x in [y.items for y in yy]]
Basically, yy is the result set of a query (Y.query.all()) and items is a relationship defined in the sqlalchemy db model. In the second loop, I am told that x has no property item but in the first loop my code is valid. I am glad that I finally got this to work but I am very confused as to why it works.
Shouldn't y.items have the same value in both cases?
Is nesting from left to right just a rule in list comprehension?