Making changes as per review by Dirk Thomas: alphabetize imports, replace itervalues with values, remove unnecessary list wrapper, move sorted(set(...)) call outside logical branch, removed unused var 'i'
Fixing topic filtering