Unbounded range()

前端 未结 1 701
Happy的楠姐
Happy的楠姐 2020-11-28 12:52

Is there an unbounded version of range (or xrange for Python 2), or is it necessary to define it manually? For example

squares = (         


        
1条回答
  •  甜味超标
    2020-11-28 13:10

    You're describing the basic use of itertools.count:

    import itertools
    squares = (x*x for x in itertools.count())
    

    0 讨论(0)
提交回复
热议问题