Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The list defined above is [1, 4, 9], but the one you just defined is [1, 4, 9, 16]. It's interesting how the shift in notation subtly confused the semantics of what's going on.


Good point. I missed that and made a mistake. It should have been:

[x * x for x in [1, 2, 3, 4] if x * x < 10]

There is a subtle shift in semantics. The functional form defines a sequence of function applications whereas the list comp notation is more of a declaration.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: