应该用 while 1
……{:10_255:} 永恒的蓝色梦想 发表于 2020-3-28 08:48
……
while 1 比 while True 快不少 本帖最后由 永恒的蓝色梦想 于 2020-3-28 09:44 编辑
def map(func,*iterables):
iterators=tuple(iter(i) for i in iterables)
try:
while True:
yield func(*(next(i) for i in iterators))
except RuntimeError:
pass 本帖最后由 zltzlt 于 2020-3-28 13:00 编辑
永恒的蓝色梦想 发表于 2020-3-28 09:08
解答错误
输入:list(map(lambda x:x+2, ))
输出:[(1,), (2,)]
预期输出:
_2_ 发表于 2020-3-28 08:50
while 1 比 while True 快不少
while True 的速度更快:
import timeit
def while_one():
i = 0
while 1:
i += 1
if i == 1000000:
break
def while_True():
i = 0
while True:
i += 1
if i == 1000000:
break
print(timeit.timeit(while_one, number=100))
print(timeit.timeit(while_True, number=100))
执行结果:
4.7106601
4.6941502999999996
页:
1
[2]