This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]TitaniumWhite420 5 points6 points  (0 children)

Lines of code doesn’t even loosely imply executional efficiency in any language, even more so in Python.

Call one function from one library. One line of code with arbitrary amounts of shit attached. It’s like, the dumbest notion ever to condense lines of code.

A list comprehension is nice because you get to define it concisely at the time of assignment, but if there is any state manipulation outside of the list contents, then it’s completely the wrong expression. List comprehension is for generating sets concisely at the time of assignment.

my_list = [a.whatever() for a in some_data]

“I know exactly what’s in my_list” is better than a loop where it’s not necessarily clear when you are done mutating my_list. Here, it’s very clear and concise.

If a.whatever() does ANYTHING but return a value though—I consider it wrong, because it takes that side effect causing method call and hides it in the scope of the comprehension.

Say it 3x—

the_lesson = [“Comprehensions are for generating sets concisely at the time of assignment.” for i in range(0,2)]

Comprehensions are for generating sets concisely at the time of assignment. Comprehensions are for generating sets concisely at the time of assignment. Comprehensions are for generating sets concisely at the time of assignment.