元组比较 [英] Tuple Comparison

查看:32
本文介绍了元组比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一本这样定义的字典:

I`ve a dictionary defined like this :

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

这些元组中的每一个都包含一个值列表(每个元组的值数量相同),如何遍历特定键的每个值以比较close"是否优于MA"?

Each one of those tuples contains a list of values ( same number of values for each tuple ), how can I iterate trough each value of paticular keys to compare if "close" is superior to "MA" ?

推荐答案

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

回复,你的评论

[...] 我想返回的是close"的一个元素是 > 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']) )

这篇关于元组比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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