我有一個元組列表看起來像這個元組的列表:過濾兩個條件
let tups = [("AA","BB",1),
("AA","CC",2),
("AA","BB",3),
("VV","RR",4),
("XX","TT",5),
("BB","BB",6)]
我想篩選出的元組只有在第一個元素是AA
和第二個元素是BB
。我試圖使用:
filter (\(x,y,_) -> x /= "AA" && y /= "BB") tups
上述命令刪除任何元組,其中所述第一元件是「AA」或第二元件是「BB」。因此,輸出是:
[("VV","RR",4), ("XX","TT",5)]
如何創建一個過濾功能,只除去元組,其中第一elemet爲「AA」,第二個要素是「BB」?正確的輸出sholuld是:
[("AA","CC",2), ("VV","RR",4), ("XX","TT",5), ("BB","BB",6)]