首页 > 解决方案 > 在 Python 中组合多个操作

问题描述

the_line = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]

b = list(range(12))
b.sort(reverse=True)

c = [i * b[i] for i in the_line]
d = sum(c)/78

有没有办法将这些操作组合成一条线?

标签: pythonlist

解决方案


d = sum(i * (11 - i) for i in the_line) / 78

如果the_line可以是别的东西:

d = sum(j * (11 - i) for i, j in enumerate(the_line)) / 78

推荐阅读