通过元素发生删除的子表(方案) [英] delete sublist by element occurrence (Scheme)
问题描述
我怎么能由它搜索只有一个ELEM删除子列表。
How I could remove a sublist by searching only one elem from it.
例如,让我们的清单:
( (pacific (atlanta ohaio) (NY LI))
(atlanta (pacific blue) (ohaio green)) )
和我想从列表中删除和平,并获得:
And I want to remove "pacific" from the list and to get:
( (pacific (atlanta ohaio) (NY LI))
(atlanta (ohaio green)) )
任何想法将大大AP preciated:)
Any ideas would be greatly appreciated :).
推荐答案
该标准从输入列表中删除一个元素没说清楚的问题。这适用于所示的例子:
The criteria for deleting an element from the input list is not stated clearly in the question. This will work for the example shown:
(define lst
'((pacific (atlanta ohaio) (NY LI))
(atlanta (pacific blue) (ohaio green))))
(map (lambda (slst)
(filter (lambda (e)
(not (and (list? e) (member 'pacific e))))
slst))
lst)
=> '((pacific (atlanta ohaio) (NY LI)) (atlanta (ohaio green)))
如果有必要,对于其他输入,可直到结果是根据需要调整状态,在最里面的lambda。举例来说,我跨preTED在问题的注释:
If necessary, for other inputs you can tweak the condition in the innermost lambda until the result is as desired. For instance, I interpreted the comment in the question:
我要删除包含搜索词的子表
I want to delete the sublist that contains the searched word
为:找到搜索词中的的任何位置的一个子表内;如果所搜索的单词,可以发现在,比方说,只有第一位置,然后相应地调整条件
As: "find the searched word in any position inside a sublist"; if the searched word can be found in, say, only the first position then adjust the condition accordingly.
这篇关于通过元素发生删除的子表(方案)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!