I have this simple piece of code that returns what’s in the title. Why doesn’t the array simply print? This is not just an itertools issue I’ve also noticed it for other code where it’ll just return the object location.
Here is the code. I’m running 2.7.1, an enthought distribution (pylab) – using it for class.
import itertools
number = [53, 64, 68, 71, 77, 82, 85]
print itertools.combinations(number, 4)
It doesn’t print a simple list because the returned object is not a list. Apply the
listfunction on it if you really need a list.itertools.combinationsreturns an iterator. An iterator is something that you can applyforon. Usually, elements of an iterator is computed as soon as you fetch it, so there is no penalty of copying all the content to memory, unlike alist.