我有一本定义如下的字典:
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/