1
$\begingroup$

I have a list which sometimes looks like:

list = {{},{}}

I need to catch these occurrences and replace them with {{0,0},0}.

The following hasn't worked

So,

If list==Null, list /. {{}, {}} -> {{0, 0}, 0},]
$\endgroup$
1
  • 2
    $\begingroup$ No need for the If statement the way you presented it. Simply list /. {{}, {}} -> {{0, 0}, 0} should do the trick. $\endgroup$ Commented Jul 15, 2016 at 23:17

1 Answer 1

3
$\begingroup$

Example

data = {{{}, {}}, {{1, 2}, {1, 1}}, {{3, 3}, {4, 4}}};
data /. {{}, {}} -> {{0, 0}, 0}

Output

{{{0, 0}, 0}, {{1, 2}, {1, 1}}, {{3, 3}, {4, 4}}}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.