我希望将全局变量值传递给timeit。
import timeit
def do2(a):
aa = []
for x in a:
for xx in x:
aa.append("".join(xx))
return aa
#t = timeit.Timer(setup="from __main__ import do1", stmt="do1()")
for _ in range(10):
xx = ["I", "have", "a", "pet"]
t = timeit.timeit("do2(xx)", "from __main__ import do2")
print(t)
我试图通过xx列表,但是它不起作用。有办法做到吗?