I would like to calculate unique values of an iterator, but without having to build a list first. Using a list, I would do for example:
from collections import Counter
from itertools import combinations
my_counts = Counter([sum(x) for x in combinations([1,2,3,4,5])],2)
But above, a list was made, and then Counter
was applied. But is there a way to keep a running tally, so that the entire list does not need to stored in memory?