我在用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.1-10元之间
一周热门 更多>