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.
x^-Length@l[[i]]should work, no? Also, a more concise alternative:AssociationMap[ Total[x^-Length@# x^Map[Length, Select[l, ContainsAll@#]]] &, l]$\endgroup$