Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Filtering a list of list for certain elements that

  • To: mathgroup at smc.vnet.net
  • Subject: [mg88859] Re: [mg88834] Filtering a list of list for certain elements that
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Mon, 19 May 2008 05:18:43 -0400 (EDT)
  • Reply-to: hanlonr at cox.net

filter[x_List, n1_, n2_] := x /. {{___, n1, n2, ___} -> Sequence[],
   {___, n2, n1, ___} -> Sequence[]}

mylist = {{a, b, c}, {a, c, b}, {b, a, c}, {b, c, a},
   {c, a, b}, {c, b, a}};

filter[mylist, a, b]

{{a, c, b}, {b, c, a}}

filter[mylist, a, c]

{{a, b, c}, {c, b, a}}

filter[mylist, b, c]

{{b, a, c}, {c, a, b}}


Bob Hanlon

---- Steven Siew <stevensiew2 at gmail.com> 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}}
> 
> 
> For this toy example, I can probably do it by hand but my real problem
> has 120 lists in a list. And I need to filter out various combination
> of letters like "s cannot be next to d" , "s cannot be next to j" , "c
> cannot be next to j" , "h cannot be next to d" and "h cannot be next
> to s".
> 



  • Prev by Date: MathLink Wrapper
  • Next by Date: Re: Filtering a list of list for certain elements that are neighbours
  • Previous by thread: MathLink Wrapper
  • Next by thread: Implementing a array assignment for custom data structure