3 ms·
`result = [i * i for i in v]` looks much more readable to me. What if you need to square every other element? copy_if and transform then don't look so pretty a
by u124556 13y ago
`result = [i * i for i in v]` looks much more readable to me.
What if you need to square every other element? copy_if and transform then don't look so pretty anymore. `result = [i * i for i in v if i % 2 == 0]` is still more readable.
What if you need to do something else and you don't know if there is a transform like function for it?
- alecbenzer 13y ago> What if you need to do something else and you don't know if there is a transform like function for it? What about the same thing in python? As far as I know the two examples you gave exhausted list comprehensions' functionality.