def average(iterable):
"""Calculate the average of an iterable of numbers."""
# 获取迭代器
it = iter(iterable)
# 获取第一个元素
total = next(it)
count = 1
# 迭代获取剩余元素的值并进行计算
for element in it:
total += element
count += 1
return total / count
def squares(n):
"""Generate the sequence of squares from 1 to n."""
for i in range(1, n + 1):
yield i ** 2
标签: seo