How can I generate a list of consecutive numbers?

前端 未结 7 770
南旧
南旧 2020-11-27 04:38

Say if you had a number input 8 in python and you wanted to generate a list of consecutive numbers up to 8 like

[0, 1, 2, 3, 4, 5,          


        
7条回答
  •  忘掉有多难
    2020-11-27 05:12

    You can use itertools.count() to generate unbounded sequences. (itertools is in the Python standard library). Docs here:
    https://docs.python.org/3/library/itertools.html#itertools.count

提交回复
热议问题