python - 在 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
有没有办法将这些操作组合成一条线?
解决方案
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
推荐阅读
- amazon-web-services - 在 CloudFront 分配中设置通配符 CNAME 时 CNAMEAlreadyExists
- firebird - 如何重置 Firebird 3.0 身份列
- java - MySQL 从左连接中选择行,在一列中具有特定数量的不同值,但没有总行限制
- c - 实现 linux shell 时的 emacs
- symfony - 在“App\Entity\Slider#user”中找不到目标实体用户
- python - 有效地确定应该属于哪个方格观测值
- c - 为什么它在 3GB 地址空间之外显示帧指针?
- regex - 如何使用perl将n个数字添加到字符串中
- java - NullPointerException:尝试在空对象引用上调用虚拟方法“void android.widget.ImageView.setImageResource(int)”
- angular - 以 Angular 形式获取自动填充的值不起作用