0
我正在嘗試編寫一個簡單的程序,用於獲取一組元素並打印出powerset。Python-chain.from_iterable返回內存地址而不是值
我使用了冪函數的配方爲python的文檔中給出:https://docs.python.org/3.4/library/itertools.html
出於某種原因,而不是返回值,它返回一個itertools.chain對象的內存地址。
它爲什麼這樣做?
from itertools import chain,combinations
def pwrst(iter):
xs = list(iter)
return chain.from_iterable(combinations(xs,n) for n in range(len(xs)+1))
s = input("Enter elements seperated by comma: ")
il = s(',')
ss = [int(x.strip()) for x in il]
pwrst(ss)