# 计算大于Python中每个'y'值的值的百分比[关闭]

##### 问题描述投票：-2回答：4
``````y = (1212, 900, 730, 714, 650, 591, 565, 500, 450, 440, 430, 420, 407, 381, 324, 315, 283)
``````

[尝试用Python编写代码以计算大于y列表中每个值的％的值。从数学上讲，每个值（第一个，第二个，第三个……直到n个总值）-1除以值的总数（在这种情况下为17个值），然后乘以100可以得到％。

1值大于900，所以（2-1/17）* 100 = 5.8

2个值大于730，所以（3rd-1/17）* 100 = 11.8

``````x = (0, 5.8, 11.8, 17.7, 23.5, 29.4, 35.3, 41.2, 47.1, 52.9, 58.8, 64.7, 70.6, 76.5, 82.4, 88.2, 94.1)
``````
python
##### 4个回答
1

``````y = (1212, 900, 730, 714, 650, 591, 565, 500, 450, 440, 430, 420, 407, 381, 324, 315, 283)

x = (lambda l: tuple(round(100 * i / l, 1) for i in range(l)))(len(y))

print(x)
``````

[我还投入了`lambda`，以防止像其他答案一样，对`len(y)`中的每个元素都评估此`y`的一线式（硬编码`y`长度的代码除外！]

``````> python3 test.py
(0.0, 5.9, 11.8, 17.6, 23.5, 29.4, 35.3, 41.2, 47.1, 52.9, 58.8, 64.7, 70.6, 76.5, 82.4, 88.2, 94.1)
>
``````

0

``````y = (1212, 900, 730, 714, 650, 591, 565, 500, 450, 440, 430, 420, 407, 381, 324, 315, 283)

y_perc = tuple([round(i/len(y)*100, 2) for i, _ in enumerate(y)])

print(y_perc)
# output: (0.0, 5.88, 11.76, 17.65, 23.53, 29.41, 35.29, 41.18, 47.06, 52.94, 58.82, 64.71, 70.59, 76.47, 82.35, 88.24, 94.12)
``````

0

``````y = (1212, 900, 730, 714, 650, 591, 565, 500, 450, 440, 430, 420, 407, 381, 324, 315, 283)

Y = tuple([round(n/len(y)*100,1) for n in range(len(y))])

print(Y)
``````

``````(0.0, 5.9, 11.8, 17.6, 23.5, 29.4, 35.3, 41.2, 47.1, 52.9, 58.8, 64.7, 70.6, 76.5, 82.4, 88.2, 94.1)
``````

0

``````y = (1212, 900, 730, 714, 650, 591, 565, 500, 450, 440, 430, 420, 407, 381, 324, 315, 283)
x = []
for i in y:
count = sum([1.0 for j in y if j > i])
x.append(round(count / len(y) * 100, 1))
print(tuple(x))
``````

``````(0.0, 5.9, 11.8, 17.6, 23.5, 29.4, 35.3, 41.2, 47.1, 52.9, 58.8, 64.7, 70.6, 76.5, 82.4, 88.2, 94.1)
``````