Greetings
Was trying to find out how to implement the coding to get all the combinations that I could get from 4 items.
Had searched through and found that in python there is such a function (itertools.combinations) for this purpose but when browse through the IA forum and seems to get the impression that the itertools library would not be imported.
Nevertheless, had tried out as follows from the python org (https://docs.python.org/2/library/itertools.html#itertools.combinations) and it didnt work as i kept getting the message “generator object at 0xa”
"generator object at 0xb " instead of what is to be expected "AB AC AD BC BD CD ".
Wonder what is missing or need to be corrected ?
Thank you
def combinations(iterable, r):
# combinations(‘ABCD’, 2) --> AB AC AD BC BD CD
# combinations(range(4), 3) --> 012 013 023 123
pool = tuple(iterable)
n = len(pool)
if r > n:
return
indices = range®
yield tuple(pool[i] for i in indices)
while True:
for i in reversed(range®):
if indices[i] != i + n - r:
break
else:
return
indices[i] += 1
for j in range(i+1, r):
indices[j] = indices[j-1] + 1
yield tuple(pool[i] for i in indices)
print combinations(‘ABCD’, 2)
abc = combinations(‘ABCD’, 2)
print abc