Using sets and generators to get rid of duplicates