Why is there no xrange function in Python3?

后端 未结 6 1108
广开言路
广开言路 2020-11-28 00:46

Recently I started using Python3 and it\'s lack of xrange hurts.

Simple example:

1) Python2:

from time import time as t
def          


        
6条回答
  •  遥遥无期
    2020-11-28 01:21

    Python3's range is Python2's xrange. There's no need to wrap an iter around it. To get an actual list in Python3, you need to use list(range(...))

    If you want something that works with Python2 and Python3, try this

    try:
        xrange
    except NameError:
        xrange = range
    

提交回复
热议问题