I have this code that gives me all possible coalitions after the Dutch elections of maximum 4 political parties. However, the output is given in numbers. I would rather have the output in the names of the parties. How do I do it?
VVD = 33;
PVDA = 9;
PVV = 20;
SP = 14;
CDA = 19;
D66 = 19;
ChristenUnie = 5;
GroenLinks = 14;
SGP = 3;
PVDD = 5;
VPLUS = 4;
DENK = 3;
FVD = 2;
Lijst := {VVD, PVDA, PVV, SP, CDA, D66, ChristenUnie, GroenLinks, SGP,
PVDD, VPLUS, DENK, FVD}
Select[Subsets[Lijst], Total[#] > 75 && Length[#] <= 4 &]
mylist = <|"a"->1, "b"->5, "c"->7|>
. For this application variables are not appropriate. Instead, bundle the name and the value together into one data structure. That can be{"name", value}
,"name" -> value
, an association like above, etc. There are lots of choices. Variables are about the worst possibility. $\endgroup$SortBy[(Select[ Thread[# -> Total[#[[All, All, 2]], {2}] ], #[[2]] > 75 &] &@ Subsets[list, 4]), Minus@*Last] // TableForm
where list = {{VVD, 33}, {PVDA, 9}, {PVV, 20}, {SP, 14}, {CDA, 19}, {D66, 19}, {ChristenUnie, 5}, {GroenLinks, 14}, {SGP, 3}, {PVDD, 5}, {VPLUS, 4}, {DENK, 3}, {FVD, 2}} $\endgroup$