![](/img/trans.png)
[英]Counting the pairs in a list such that their first index is less than the second but the first element is greater than the second
[英]How can i check in first List index 1 is greater than second list index 0, and first List index 2 is greater than second list index 1. and so on
我有三個列表-
High: [18365.5, 18979.25, 19297.4, 19874.8, 20288.0, 20504.65, 20398.2]
Low: [17855.5, 18265.0, 18822.55, 18742.15, 19492.55, 20055.55, 20131.25]
Close: [18317.05, 18969.95, 18857.6, 19804.0, 20260.15, 20285.0, 20215.7]
我想檢查
if Close [index1] > Low [index0]
print("XYZ")
elif Close[index1] < High[index0]
print("XYZ")
並且對於索引的 rest 也是如此。
if Close [index2] > Low [index1]
print("XYZ")
elif Close[index2] < High[index1]
print("XYZ")
請幫我解決這個問題。 我不明白我該怎么做。
根據您的要求解決。
考慮到其股票市場,正確的解決方案是檢查所有列表的相同索引。
high = [18365.5, 18979.25, 19297.4, 19874.8, 20288.0, 20504.65, 20398.2]
low = [17855.5, 18265.0, 18822.55, 18742.15, 19492.55, 20055.55, 20131.25]
close = [18317.05, 18969.95, 18857.6, 19804.0, 20260.15, 20285.0, 20215.7]
for i in range(len(high)-1):
if (close[i+1] > low[i]) and (close[i+1] < high[i]):
print("Valid Indices")
else:
print("Invalid: Correct Sequence: Low < Close < High")
建議:低=<收盤=<高
您可以zip
這三個列表並對其進行迭代。 確保正確切片Close
以便評估正確的項目:
for (high, low, close) in zip(High, Low, Close[1:]):
if close > low:
print("S")
elif close < high:
print("L")
else:
continue
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.