0
$\begingroup$

I have a nested list which looks like:

nested_list

and I would like to count the following:

  • all sublists containing {n_,n_} && {n_,n_,n_}
  • all sublists containing {l_,l_} && {l_,l_,l_}
  • all sublists with any combination of the above like {l_,n_} or {n_,l_,l_} or {n_,n_,l_}

in addition I would like to separate those cases when I have {l_,l_,l_} with text on it like the one highlighted. Any suggestion is really appreciated

$\endgroup$
3
  • 2
    $\begingroup$ Sorry, I do not see a single string. $\endgroup$ Commented Dec 6, 2018 at 15:48
  • $\begingroup$ I mean those that contain PoP, VNF or MANO despite they have a number on it. However, currently I am trying an approach like , substituting all the elements with very different numbers and then count those that are >/< than a certain sum. I will let it know if it works. $\endgroup$
    – Besi
    Commented Dec 6, 2018 at 15:56
  • 2
    $\begingroup$ Please do not only attach a screenshot, but also post some codes. $\endgroup$ Commented Dec 6, 2018 at 15:59

1 Answer 1

3
$\begingroup$

You should provide copy/pastable input. Here is a random example list:

rlist := With[{len = RandomInteger[{2, 3}]},
    MapThread[Subscript, {RandomChoice[{n, l}, len], RandomInteger[10, len]}]
]

SeedRandom[1]
list = Table[rlist, 20];
list //TeXForm

$\left\{\left\{l_1,n_4,l_0\right\},\left\{l_8,l_0\right\},\left\{l_1,n_8\right\},\left\{n_{10},l_8\right\},\left\{n_8,l_5\right\},\left\{l_1,l_1,l_1\right\},\left\{n_9,l_6\right\},\left\{l_8,n_7\right\},\left\{n_8,n_0,l_9\right\},\left\{n_2,n_5,l_3\right\},\left\{n_0,n_4,n_7\right\},\left\{l_{10},l_6\right\},\left\{n_3,n_2\right\},\left\{n_3,l_9,l_5\right\},\left\{n _{10},n_1\right\},\left\{l_4,l_4\right\},\left\{n_{10},l_8\right\},\left\{n_2,n_5,n_6\right \},\left\{l_3,l_3,l_1\right\},\left\{l_0,n_{10}\right\}\right\}$

Then, you can use Tally to obtain your desired counts:

Tally[Union /@ list[[All, All, 1]]]

{{{l, n}, 11}, {{l}, 5}, {{n}, 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.