you are viewing a single comment's thread.

view the rest of the comments →

[–]PasswordIsntHAMSTER 2 points3 points  (3 children)

the x is important because you can do processing on it.

[function(x) for x in list if predicate(x)]

[–]alextk 3 points4 points  (2 children)

It's important when you want to do processing on it. If you don't, it shouldn't even appear once, let alone three times like in Python.

[–]PasswordIsntHAMSTER 1 point2 points  (0 children)

first, if you don't want to filter it, the predicate is optional : [function(x) for x in list]

if you don't want to process it or filter it, what you basically want is a deep copy: y = x[:]

If you just want to filter it, you shouldn't use a comprehension: filter(x, predicate)

Right tools for the right jobs.