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$
  • 2
    $\begingroup$ No need for the If statement the way you presented it. Simply list /. {{}, {}} -> {{0, 0}, 0} should do the trick. $\endgroup$ – Jack LaVigne Jul 15 '16 at 23:17
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, privacy policy and cookie policy

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