檢查一些代碼,我看到如下內容:
// This snippet is from the variables display in VS code while debugging and psuedocode:
theIndex: (1, 1)
myDataa['aKeyPhrase'][a secondary group of arrays]
所以 myData 的第一個索引是 'aKeyPhrase',它是一個變化的變數并且是一個唯一的字串,如下所示:
aKeyPhrase = 'labelA'
aKeyPhrase = 'labelB', etc.
myData 的第二部分包含一組數字,因此theIndex: (1, 1)指的是該組的第一個索引和第二個索引:
// (1, 1) would be refering the numbers 24.0 and 18.0
{1: 24.0, 2: 10.0, 3: 34.0}
{1: 18.0, 2: 23.0, 3: 32.0}
在我對 myData 做任何事情之前,我想檢查 theIndex 是否存在以及它是否等于 '%' 并執行以下操作:
if theIndex not in myData[aKeyPhrase] or myData[aKeyPhrasel][theIndex] == '%':
上面那個運算式的第一部分總是false. 這應該是正確的,因為索引存在于 myData 樣本中。如何正確檢查?
uj5u.com熱心網友回復:
IIUC,theIndex是一個元組,myData[aKeyPhrase]是一個字典串列,對于theIndex = (1, 2),1 對應于第一個字典的鍵,2 是第二個字典的鍵,對嗎?在那種情況下,在 if 條件下,if theIndex not in myData[aKeyPhrase]將始終回傳 False。您可以將其修改為
if all(i in d for i, d in zip(theIndex, myData[aKeyPhrase])) or myData[aKeyPhrasel][theIndex] == '%'
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/427616.html
上一篇:如何添加到List<int,string>動態id(int)內部的每個專案(字串),這實際上是內部每個元素的位置?
