0
$\begingroup$

I have the following list,

l = {{"a", "b"}, {"a", "b"}, {"c", "d"}, {"e", "f"}, {"e", "f"}, {"x", "y", "z"}, {"m", "n", "o"}, {"p", "q", "s"}}; 

for each sublist I want to count them and make a polynomial out of it, for example for {"a", "b"} I have

Total[x^-2 x^Map[Length, Select[l, ContainsAll[{"a", "b"}]]]] 

Note that the x^-2 terms is important to be there for my later calculations. Now if I want to do this for {"x","y","z"} I shall do

Total[x^-3 x^Map[Length, Select[l, ContainsAll[{"x", "y","z"}]]]] 

So as you see the power of first term is now x^-3, now if I want to do this on a table I can write,

AssociationThread[ l -> Table[ Total[x^-i x^Map[Length, Select[l, ContainsAll[l[[i]]]]]], {i, Length[l]}]] 

My question is how to iterate the x^-i such that it works correspondingly? meaning for entries of length 2 the power should be x^-2, for entries of length 3 the power should be x^-3 and generalisable to higher length in similar manner.

$\endgroup$
2
  • 2
    $\begingroup$ If I understand you correctly, x^-Length@l[[i]] should work, no? Also, a more concise alternative: AssociationMap[ Total[x^-Length@# x^Map[Length, Select[l, ContainsAll@#]]] &, l] $\endgroup$ Commented Sep 10, 2019 at 12:07
  • $\begingroup$ Thank you that is indeed sorted it :) $\endgroup$ Commented Sep 10, 2019 at 12:11

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.