x = y = 0 #sorts the data into spin up or spin down, then in required eV range
for x in range(0,len(BSlist)):
if 'Spin.Up' in BSlist[x]:
for y in range (x+1,x+(Count)):
if (float(BSlist[y].split()[1]) >= -2.0) and (float(BSlist[y].split()[1]) <= 2.0):
UpList1.extend(BSlist[x:(x+(Count))])
x = ((x // Count) * (Count)) + Count
continue
if 'Spin.Down' in BSlist[x]:
for y in range (x+1,x+(Count)):
if (float(BSlist[y].split()[1]) >= -2.0) and (float(BSlist[y].split()[1]) <= 2.0):
DnList1.extend(BSlist[x:(x+(Count))])
x = ((x // Count) * (Count)) + Count
continue
UpList2 = []#changing to csv form
x = y = 0
for x in range(0,Count):
UpList2.append(str(x))
if x != 0:
y = x
UpList2[x] = UpList2[x] + '\t' + UpList1[x].split()[0] + '\t' +
UpList1[x].split()[1]
while y in range(0,len(UpList1)):
UpList2[x] = UpList2[x] + '\t' + UpList1[y].split()[1]
y = y + Count
if 'Spin.Up' in UpList1[x]:
while y in range(0,len(UpList1)):
UpList2[x] = UpList2[x] + '\t' + UpList1[y][UpList1[y].find('Band'):
(UpList1[y].find('Band')+9)]
y = y + Count
程序的這一部分以預先存儲在一個列表中,並對其進行排序成兩個單獨的列表60個的數據點不排序基於設定的範圍的值。之後,它應該通過列表中的每個數據點並檢查它們是否在大於或等於-2.0且小於或等於2.0的範圍內。但是,它只輸出介於-2.0和8.0之間的數據。我們想知道這是否是語法問題,因爲它似乎忽略了小於或等於2.0的第二條語句。蟒3.5使用布爾運算符
能告訴你數據的樣本(BSlist'的'內容)? –
https://i.stack.imgur.com/LSA1f.png 下面是一張圖片的鏈接,該圖片顯示了不應打印到列表中的數據示例。如果你看右側,你會發現沒有一個值低於2.000 ...我們試圖排除這些數據,但它包含在輸出中。 – rprog
所以,基本上,'BSlist'是一個字符串列表,每個字符串都包含兩個浮點數,並且只有這些數字中的第二個是感興趣的,對嗎? –