The itertools function has no error but it also doesn’t print anything once its complete.
My code is:
def comb(iterable, r):
pool = tuple(iterable)
n = len(pool)
for indices in permutations(range(n), r):
if sorted(indices) == list(indices):
print (indices)
yield tuple(pool[i] for i in indices)
I included the print statement but it doesn’t print the total combinations it calculated.
You need to read up on how generators work. When you call
comb()it returns a generator object. You need to then do something with the generator object to get the objects returned from it.comb()returns a generator object. Then,list()iterates it and collects the values in a list. At the time of iteration, your print statement fires.