CoffeeScript list comprehensions are slightly different from Pythons… which of these is the way that people like to return list comprehensions?
return elem+1 for elem in [1,2,3] # returns 3+1
return [elem+1 for elem in [1,2,3]].pop() # returns [2,3,4]
return (elem+1 for elem in [1,2,3]) # returns [2,3,4]
In Python, I would just write:
return [elem+1 for elem in [1,2,3]]
And it returns the list correctly, instead of a list of lists, as this would do in CoffeeScript.
Well, of the three options, certainly #3. But the best stylistic choice is actually this:
As the last line of a function, any expression
expris equivalent toreturn (expr). Thereturnkeyword is very rarely necessary.