Python 从一个范围中获取两个值

Python 从一个范围中获取两个值,python,lambda,iterator,Python,Lambda,Iterator,我有: 输出是预期的,但是有更好的方法获得它吗?例如,以我得到的方式: >>> se = iter(map(lambda x: (x, x + 1), range(5))) >>> print("{:d} {:d}".format(*(next(se)))) 0 1 您可以使用而不是map+lambda: >>> print("{:d} {:d}".format(se)) 0 1 并且,您可以使用格式字符串中的索引: >&g

我有:

输出是预期的,但是有更好的方法获得它吗?例如,以我得到的方式:

>>> se = iter(map(lambda x: (x, x + 1), range(5)))
>>> print("{:d} {:d}".format(*(next(se))))
0 1
您可以使用而不是
map
+
lambda

>>> print("{:d} {:d}".format(se))
    0 1
并且,您可以使用格式字符串中的索引:

>>> se = ((x, x+1) for x in range(5))
>>> next(se)
(0, 1)
>>> next(se)
(1, 2)


如果要在迭代器上进行迭代,可以在迭代器解包时使用
for
语句:

>>> '{0[0]} {0[1]}'.format(next(se))
'0 1'

谢谢,我被超级蟒蛇迷住了。
>>> se = ((x, x+1) for x in range(5))
>>> for a, b in se:
...     print('{} {}'.format(a, b))
... 
0 1
1 2
2 3
3 4
4 5