题型:python2
import disfinal_result = {}
def sales_sim():
total = 0
nums = []
while 1:
val = yield
if val is None:
break
total += val
nums.append(val)
return total, nums
def middle(key):
while 1:
final_result[key] = yield from sales_sim()
def main():
data_sets = {"mm": [1200, 1500, 3000], "sj": [28, 55, 98, 108], "dy": [280, 560, 778, 70]}
for key, value in data_sets.items():
m = middle(key) # [1,2,3,4] # [1]
# print(m)
m.send(None)
for i in value:
m.send(i)
m.send(None)
if __name__ == '__main__':
# dis.dis(main)
main()
print(final_result)
#{'mm': (5700, [1200, 1500, 3000]), 'sj': (289, [28, 55, 98, 108]), 'dy': (1688, [280, 560, 778, 70])}
以上是 题型:python2 的全部内容, 来源链接: utcz.com/z/386730.html