Fix py3k incompatibility with itertools.ifilter

This patch fixes the incompatibility and makes the code more efficient
at the same time, by simply moving the filter logic directly into the
list comprehension.

Change-Id: I8859b4a93bec883163d1c4cc373374a105cfe0bb
Merge "Fix py3k incompatibility with itertools.ifilter"