I have a list:
lis = {{"b","x","d"},{"a","z","b"},{"a","x","b"},{"a","x","c"},{"b","z","d"}}
Certain consecutive elements of this list will have identical first and last members (in this example, "a"
and "b"
in lis[[2]]
and lis[[3]]
) and I would like to delete the element that has "x" as its middle element, to give:
res = {{"b","x","d"},{"a","z","b"},{"a","x","c"},{"b","z","d"}}
It seems like a job for SequenceCases, but am having no luck.
DeleteDuplicatesBy
. $\endgroup$Split[lis, #1[[1]] == #2[[1]] && #1[[3]] == #2[[3]] &]
to group the consecutive elements. $\endgroup$