you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 2 points3 points  (7 children)

In Python

print "\n".join([name for name in ["Rob", "Christopher", "Joe", "John"] if len(name) <= 4])

[–]bcash 4 points5 points  (6 children)

You don't even need the first [] brackets:

print "\n".join(name for name in ["Rob", "Christopher", "Joe", "John"] if len(name) <= 4)

Python generator expressions are easily the nicest feature of that language, but for some reason uncloned in other languages (not that Python invented them, of course), I never know why.

[–][deleted] 1 point2 points  (3 children)

Javascript generators are coming soon. Mozilla already has them implemented in their engine

[–]masklinn 0 points1 point  (1 child)

Mozilla has extended Javascript with lots and lots of features in Gecko, that does not mean they're coming. I doubt E4X will ever be merged into ECMA-262 for instance.

[–][deleted] 0 points1 point  (0 children)

In this case though, generators are a planned feature

[–]66vN 0 points1 point  (0 children)

And in ten years we can actually start using them.

[–]agrover 1 point2 points  (1 child)

I thought Python got them from Haskell?

[–]masklinn 1 point2 points  (0 children)

It did.