Tuple Comparison

前端 未结 2 556
谎友^
谎友^ 2021-01-24 21:46

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(m         


        
2条回答
  •  感动是毒
    2021-01-24 22:12

    From the Python docs:

    Tuples and lists are compared lexicographically using comparison of corresponding elements. This means that to compare equal, each element must compare equal and the two sequences must be of the same type and have the same length.

    If not equal, the sequences are ordered the same as their first differing elements. For example, cmp([1,2,x], [1,2,y]) returns the same as cmp(x,y). If the corresponding element does not exist, the shorter sequence is ordered first (for example, [1,2] < [1,2,3]).

    So as @TokenMacGuy says, you can simply use d['close'] > d['MA'] to compare the respective tuples.

提交回复
热议问题