回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我有一个数据列表:</p>
<p>[18.0,18.0,28.35,81.26,1.99,1.3,1.4,1.4,1.4,1.4,14.8,1.78,5.79,21.18,2.54,3.0,1.69,8.11,1.57,1.31,11.19,8.14,1.42,4.72]</p>
<p>我想当其中两个数字的值小于2时,第三个数字存储在另一个列表中。例如,如果前两个数字小于2;第三个数字进入列表,当第三个和第四个数字小于2时,第五个数字也在列表中。
但问题是,如果几个连续系数小于2,程序将难以识别正确的系数。
我的代码是:</p>
<pre><code>for listItrator in listOfCoefficients_float:
if listItrator < lowCoefficientsCounter: #lowCoefficientsCounter: Is equal to 2 as assumed
wait = wait + 1
if wait == wait2: #wait2: This variable is entered by the user, which according to the pattern described at the beginning of the problem, is equal to 2 here
trimmedCofficientsFiller = listOfCoefficients_float.index(listItrator)
finalOutputCofficients_float.append(float(listOfCoefficients_float[trimmedCofficientsFiller + 1])) #Save the next coefficient in the list
wait = 0
elif listItrator >= lowCoefficientsCounter:
wait = 0
</code></pre>
<p>输出列表为:
[1.4,1.4,1.4,1.19]</p>
<p>而我期望的输出是:
[1.4,1.4,14.8,11.19]</p>