从性能和编码风格的角度来看,这两种方法是否等效?
def foo(n):
return n*2
# case 1 with ".append(function())"
mylist = [1,2,3,4,5,6,7,8,9,10]
result = list()
for l in mylist:
result.append(foo(l))
# case 2 ".append(result)"
mylist = [1,2,3,4,5,6,7,8,9,10]
result = list()
for l in mylist:
r = foo(l)
result.append(r)