python - 元组比较

标签 python tuples

我有一本定义如下的字典:

d = {"date": tuple(date),"open":tuple(open),"close":tuple(close),"min":tuple(min),"max":tuple(max),"MA":tuple(ma)}

每个元组都包含一个值列表(每个元组的值数量相同),如何迭代特定键的每个值来比较“close”是否优于“MA”?

最佳答案

我错过了什么? d['close'] > d['MA']?

编辑:回复,您的评论

[...] what I want to return is how many times one element of "close" is > to the matching element of MA . (same tuple index)

sum( pair[0] > pair[1] for pair in zip(d['close'], d['MA']) )

关于python - 元组比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4405122/

相关文章:

python读取mat文件日期时间数组

java - 元组,从 Python 到 Java

c++ - 元组头中对函数 std::get<1> 的引用

haskell - 从已经存在的对象构造元组(或列表) - 成本是多少?

python - python中的变量赋值查询

python - 为单元格添加背景颜色,reportlab python

c# - 为什么在 C# 中使用 1 元组 Tuple<T1>?

python - for 循环如何在元组中工作

python - 带有 json.dump 的 JSON 对象之间的逗号分隔符

python - Scrapy:使用 CloudFlare 抓取网站时出现 503 错误