Hi,
list2 is a subset of list1.
list1 = {a, b, c, d, e, c, a}; list2 = {e, c, a};
I would like to have the following output?
{a, b, c, d}
Hi Alex,
with Drop[list1, -3] you simply drop the last 3 elements, list2 then is not necessary at all. This is a different task.
Drop[list1, -3]
list2
ResourceFunction["MultisetComplement"] will do this.
ResourceFunction["MultisetComplement"]
https://resources.wolframcloud.com/FunctionRepository/resources/MultisetComplement
Alex:
If there are no repeated items in your lists, then you can use Complement[].
If you have to handle repeated items, as in your first post. Then one way to go about it would be to:
I don't have time to build this function right now. But I hope this helps.
Hi Henrik,
Thank you so much. I used the "Drop" command for deleting a subset of numbers from the main list. Is it correct?
list1 = {6, 3, 8, 11, 20, 6, 14, 3, 0}; list2 = {14, 3, 0}; Drop[list1, -3] {6, 3, 8, 11, 20, 6}
as far as I understand your question one way would be to do it using strings; the substantial work is done by StringDelete:
StringDelete
string1 = StringJoin[ToString /@ list1]; string2 = StringJoin[ToString /@ list2]; ToExpression@Characters@StringDelete[string1, string2]
Does that meet your requirement? Regards -- Henrik