这段代码如何Pythonic [for] 财富值49

2016-10-14 17:08发布

我在用plt画饼状图。如下是简化的代码。

a_part = [2001, 12000] b_part = [1001, 2000] c_part = [11, 1000] d_part = [1, 10]  data = range(1, 12000) labels = [a_part, b_part, c_part, d_part] sizes = [] for part in labels:     sum = 0     for each in data:         sum += each if each >= part[0] and each <= part[1] else 0     sizes.append(sum) print(sizes)

其中这段代码如何Pythonic?

for part in labels:     sum = 0     for each in data:         sum += each if each >= part[0] and each <= part[1] else 0     sizes.append(sum)
友情提示: 问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
0条回答

一周热门 更多>