can this be written in one line without List Comprehensions?
for x in vec:
if x > 3:
...
...
See @KennyTM... no reason to compress that much.
What being said, for x in (i in vec if i > 3)
does the job, as well as itertools.ifilter
(or just the builtin filter
in Python 3) with a lambda x: x > 3
predicate. They work with all iterables as well, and are lazy (e.g. if you break
during the loop, you didn't check a single item too much).