这是一个从列表中获取最小值、最大值和平均值的简单示例。下面的两个函数有相同的结果。我想知道这两个函数之间的区别。为什么要使用itertools.tee()?它提供了什么优势?
from statistics import median
from itertools import tee
purchases = [1, 2, 3, 4, 5]
def process_purchases(purchases):
min_, max_, avg = tee(purchases, 3)
return min(min_), max(max_), median(avg)
def _process_purchases(purchases):
return min(purchases), max(purchases), median(purchases)
def main():
stats = process_purchases(purchases=purchases)
print("Result:", stats)
stats = _process_purchases(purchases=purchases)
print("Result:", stats)
if __name__ == '__main__':
main()
MYYA
相关分类