返回顶部

收藏

mxrange 模拟 系统 xrange

更多
def mxrange(start,end=0,step=1):
    (start,end) = start>end and (end,start) or (start,end)
    while start < end:
        yield start
        start+=step      

print [i for i in xrange(5)],[i for i in mxrange(5)]
print [i for i in xrange(1,5)],[i for i in mxrange(1,5)]
print [i for i in xrange(4,5,2)],[i for i in mxrange(4,5,2)]
'''
[0, 1, 2, 3, 4] [0, 1, 2, 3, 4]
[1, 2, 3, 4] [1, 2, 3, 4]
[4] [4]
'''

标签:python

收藏

0人收藏

支持

0

反对

0

发表评论