返回清单的产品
有没有更简洁,有效或简单的pythonic方法来执行以下操作? def product(list): p = 1 for i in list: p *= i return p 编辑: 我实际上发现这比使用operator.mul快一点: from operator import mul # from functools import reduce # python3 compatibility def with_lambda(list): reduce(lambda x, y: x * y, list) def without_lambda(list): reduce(mul, list) def forloop(list): r = 1 for x in …