Python returning `` - How can I access this?

后端 未结 2 929
抹茶落季
抹茶落季 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

    It doesn't print a simple list because the returned object is not a list. Apply the list function on it if you really need a list.

    print list(itertools.combinations(number, 4))
    

    itertools.combinations returns an iterator. An iterator is something that you can apply for on. 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 a list.

提交回复
热议问题