Python returning `` - How can I access this?

后端 未结 2 931
抹茶落季
抹茶落季 2020-12-24 07:17

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 notice

2条回答
  •  我在风中等你
    2020-12-24 07:47

    Try this:

    for x in itertools.combinations(number, 4):
       print x
    

    Or shorter:

    results = [x for x in itertools.combinations(number, 4) ]
    

    Basically, all of the itertools module functions return this type of object. The idea is that, rather than computing a list of answers up front, they return an iterable object that 'knows' how to compute the answers, but doesn't do so unless `asked.' This way, there is no significant up front cost for computing elements. See also this very good introduction to generators.

提交回复
热议问题