3
$\begingroup$

Say we have a list

l = {4x,3y,z}

When we do

Count[l,x]

we get, as expected

0

Is there a function, call it F, that takes multiplicities into account, so for example for l

F@l

{4,3,1}

or equivalently a function that extracts multiplicities of each element in a list?

$\endgroup$
1
  • 3
    $\begingroup$ Your example is probably too simplistic to really represent what you want. For example, F = Coefficient[#, {x, y, z}] & works just fine. Is this what you want? Is there a more complex example where this does not work? $\endgroup$ May 29 '19 at 17:00
4
$\begingroup$

You could use FactorTermsList:

First @* FactorTermsList /@ {4 x, 3 y, z}

{4, 3, 1}

$\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.