Victor Gunnarsson
Victor Gunnarsson

Reputation: 320

Filter out elements in tuple from list of tuples

I have an list of tuples looking like this:

[("APPLE",["APPLE","BANANA","PEAR"]),("ANANAS",["ANANAS","BANANA","APPLE"])]

However I would like to remove any occurrence of the first element in the tuple from the snd list in the tuple. So I would like the list of tuples to look like:

[("APPLE",["BANANA","PEAR"]),("ANANAS",["BANANA","APPLE"])]

Upvotes: 2

Views: 57

Answers (1)

Victor Gunnarsson
Victor Gunnarsson

Reputation: 320

I solved it using:

map (\(x, y) -> (x, filter (/=x) y)) list

Upvotes: 4

Related Questions