如何对元组内一组列表中的第一个值求和? [英] How do I sum the first value in a set of lists within a tuple?

查看:25
本文介绍了如何对元组内一组列表中的第一个值求和?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我希望能够执行 this 但要对我总结的列表有选择性.比方说,同样的例子,但只将第 3 个和第 4 个列表中的第一个数字相加.

Hey, I would like to be able to perform this but with being selective for which lists I sum up. Let's say, that same example, but with only adding up the first number from the 3rd and 4th list.

推荐答案

类似:

sum(int(tuple_list[i][0]) for i in range(3,5))

range(x, y) 生成从 x(included) 到 y(excluded) 和 1 作为步长的整数列表.如果你想改变 range(x, y, step) 也会做同样的事情,但要逐步增加.

range(x, y) generates a list of integers from x(included) to y(excluded) and 1 as the step. If you want to change the range(x, y, step) will do the same but increasing by step.

您可以在此处

或者你可以这样做:

sum(float(close[4]) for close in tickers[30:40])

这篇关于如何对元组内一组列表中的第一个值求和?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆