I have two lists
l1 = {{{1,2},1},{{3,4},2},{{1,3},3}};
l2 = {{{1,2},2},{{3,5},2},{{1,3},3}};
My goal is to have a function that, if the first element of an element of l1
is the same as the first element of an element of l2
, it has to subtract the second element of the element of l2
to the one on l1
. If not, just append to the list.
For example, the goal here would be to return
{{{1,2},-1},{{3,4},2},{{3,5},2},{{1,3},0}};
I do know how to do this with for
and while
, but I feel that that's not the mathematica way, as I want it.
EDIT:
The lengths of l1
and l2
might vary and the first pair could be any real number. The second element it is indeed a positive integer.
l2
contains a pair{{a,b},c}
thatl1
has, then will it be at the same index as it is inl1
? $\endgroup${a,b}
within each list guaranteed to be unique? $\endgroup${a,b}
ofl1
might appear onl2
. $\endgroup$