def filterStopwords(self, counter: collections.Counter, stopListPath: str) -> collections.Counter: wordList = [] for i in counter.elements(): wordList.append(i) stopSets = self.generateStopSets(stopListPath) filterRes = filter( lambda i: not stopSets.__contains__(i) and i != '' and i != ' ', wordList) return collections.Counter(filterRes)
def intersect(nums1, nums2): a, b = map(Counter, (nums1, nums2)) return list((a & b).elements()) Counter.elements()