You can implement a quick counter with  `collections.defaultdict(lambda: 0)` and skip the `if tree in uniques`.