Does itertools.product evaluate its arguments lazily?

前端 未结 3 1129
感情败类
感情败类 2020-12-03 22:49

The following never prints anything in Python 3.6

from itertools import product, count

for f in product(count(), [1,2]): 
    print(f)

Ins

3条回答
  •  孤街浪徒
    2020-12-03 23:15

    I found that

    for tup in ((x,y) for x in count() for y in [1,2]):
        print(tup)
    

    does what I expect. This is odd given that it is listed as equivelent in the docs. This seems like a bug in itertools.product, but it seems unlikely given how standard it is.

提交回复
热议问题