如下,为什么两个的结果不一样呢?求大佬指点一下方向。
C:\source\pythonProject>type yield_list.py
def combinations(hay, n, path):
if len(path) == n:
yield path
return
for x in hay:
if path and (x in path or x < min(path)):
continue
path.append(x)
yield from combinations(hay, n, path)
path.pop()
print(list(combinations(['A', 'B', 'C'], 2, [])))
print('>>>>>>>>>>>>>>>>')
for x in combinations(['A', 'B', 'C'], 2, []):
print(x, end=', ')
C:\source\pythonProject>python --version
Python 3.10.7
C:\source\pythonProject>python yield_list.py
[[], [], []]
>>>>>>>>>>>>>>>>
['A', 'B'], ['A', 'C'], ['B', 'C'],
C:\source\pythonProject>
--
FROM 116.24.65.*