Reversing Grouped Lists
KeyValueMap[Thread[#1 -> #2] &, list] // Flatten // Map[Association]
Association /@ Flatten[Table[Thread[key -> list[key]], {key, Keys[list]}], 1]
Using ideas from this answer by Leonid:
unMerge = Catenate @* MapIndexed[Association /@ Thread[#2[[1, 1]] -> #] &];
unmerged = unMerge @ list
{<|"Net1" -> {"counteroffensive", "nonpayment", "dieresis"}|>,
<|"Net1" -> {"suffragan", "identifiably"}|>,
<|"Net2" -> {"psychiatrist", "pusher", "generous", "praising", "thy"}|>,
<|"Net2" -> {"amplification", "amylase", "shooting", "tumbler", "mimosa", "dengue"}|>}
Merge[Identity] @ unmerged == list
True
Another way to use MapIndexed
:
unMerge2 = Map[Association] @* Catenate @* MapIndexed[Thread[#2[[1, 1]] -> #] &];
unMerge @ list == unMerge2 @ list
True
Also:
unMerge3 = Query[Catenate @* Map[KeyValueMap[Association @* Rule]] @* Transpose];
Sort @ unMerge @ list == Sort @ unMerge3 @ list
True
If the output from GeneralUtilities`AssociationTranspose
is acceptable, you can also use:
Query[Transpose] @ list
{<|"Net1" -> {"counteroffensive", "nonpayment", "dieresis"}, "Net2" -> {"psychiatrist", "pusher", "generous", "praising", "thy"}|>,
<|"Net1" -> {"suffragan", "identifiably"}, "Net2" -> {"amplification", "amylase", "shooting", "tumbler", "mimosa", "dengue"}|>}