match List1 in List2

Hakan Mattsson hakan@REDACTED
Wed Sep 18 10:33:38 CEST 2002


On Wed, 18 Sep 2002, Vance Shipley wrote:

Vance> What would be the best way to return the list of tuples
Vance> in List1 which match the tuples in List2?
Vance> 
Vance> List1 = [{foo, 13}, {bar, 42}, {fooz, 67}]
Vance> List2 = [{baz, 15}, {booz, 145}, .....]
Vance> 
Vance> It seems to me that this should be a one liner but I've
Vance> not found the simple solution yet.

This perhaps?

  1> List1 = [{foo, 13}, {bar, 42}, {fooz, 67}].
  [{foo,13},{bar,42},{fooz,67}]
  2> List2 = [{baz, 15}, {booz, 145},{fooz,67}].
  [{baz,15},{booz,145},{fooz,67}]
  3> [A || A <- List1, B <- List2, A == B].
  [{fooz,67}]
  4> 

/Håkan



More information about the erlang-questions mailing list