Re: Filtering a list of list for certain elements that are neighbours
- To: mathgroup at smc.vnet.net
- Subject: [mg88841] Re: Filtering a list of list for certain elements that are neighbours
- From: Bill Rowe <readnews at sbcglobal.net>
- Date: Mon, 19 May 2008 05:15:11 -0400 (EDT)
On 5/18/08 at 7:34 AM, stevensiew2 at gmail.com (Steven Siew) wrote:
>I have a list of lists
>mylist={{a,b,c},{a,c,b},{b,a,c},{b,c,a},{c,a,b},{c,b,a}}
>I want to filter out all lists that have "a being a neighbor to b".
>I am looking for the following result.
>{{a,c,b},{b,c,a}}
Here is one way
In[13]:= Fold[
DeleteCases[#1, #2] &, mylist, {{___, a, b, ___}, {___, b, a, ___}}]
Out[13]= {{a, c, b}, {b, c, a}}