list刪除和挑選,list刪除挑選
clean函數用於刪除合格list元素,filter函數用於挑選合格list元素
(clean symbol? '(1 2 d 4 f g 5 h)) → (1 2 4 5)(filter symbol? '(1 2 d 4 f g 5 h)) → (d f g h)(define (big? x) (> x 5)) → (lambda (x) (> x 5))(clean big? '(1 10 3 6 4 5 11)) → (1 3 4 5)(clean <= '(3 4 -6 0 2 -3 0)) → (3 4 2)(clean (curry match '(a *)) '((a 10) (b 5) (a 3) (c 8) (a 9)))→ ((b 5) (c 8))
clean 結合lambda以及member函數,可以先定一個list,裡麵包含所有要剔除的元素,然後對另一個list操作,該list中的元素只要出現在第一個list中,就一定會被剔除。
下面的a是一個字串,先轉換成list,然後用unique去掉多餘的空格,只留下一個空格,最後用clean + lambda + member將最後一個空格去除。 這樣string就變成了list.
> a"1 2 3 4"> (explode a)("1" " " "2" " " "3" " " "4")> (unique (explode a))("1" " " "2" "3" "4")> (clean (fn (p) (member p '(" "))) (unique (explode a)))("1" "2" "3" "4")
比如下面的代碼可以用來將目錄下.和..的檔案刪除掉:
(clean (fn (p) (member p '("." ".."))) (directory dir-path))
vb怎刪除list中的選項
Private Sub Command1_Click()
For i = 0 To List1.ListCount - 1
If InStr(List1.List(i), "BC") > 0 Then List1.RemoveItem i
Next
End Sub
vb list刪除選定行後自動跳到下一個
Private Sub List1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 46 And List1.ListIndex > -1 Then
a = List1.ListIndex
List1.RemoveItem List1.ListIndex
If a <> List1.ListCount Then
List1.ListIndex = a
Else
List1.ListIndex = a - 1
End If
End If
End Sub