# Nested list manipulation - extract info about frequency

The output of MovingMap with a nested Tally will result in a list of nested lists. For example:

dex = {x, x, x, z, x, v, x, v, v, z, z, v, x, z, v, z, z, x}

sol = MovingMap[Tally, dex, Quantity[3, "Events"]]

{{{x, 3}}, {{x, 2}, {z, 1}}, {{x, 2}, {z, 1}}, {{z, 1}, {x, 1}, {v,
1}}, {{x, 2}, {v, 1}}, {{v, 2}, {x, 1}}, {{x, 1}, {v, 2}}, {{v,
2}, {z, 1}}, {{v, 1}, {z, 2}}, {{z, 2}, {v, 1}}, {{z, 1}, {v,
1}, {x, 1}}, {{v, 1}, {x, 1}, {z, 1}}, {{x, 1}, {z, 1}, {v,
1}}, {{z, 2}, {v, 1}}, {{v, 1}, {z, 2}}, {{z, 2}, {x, 1}}}

The aim is to create from list "sol" a new list containing frequency values so it would look like the following

{3,2,1,2......}

Thank you in advance for suggestions

• Maybe just sol // (Nest[Map, Last, 2] /* Catenate)? Feb 5, 2019 at 20:05

Last /@ Flatten[sol, 1]

{3, 2, 1, 2, 1, 1, 1, 1, 2, 1, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 2, 1}

Join @@ MovingMap[Values@*Counts, dex, Quantity[3, "Events"]]

{3, 2, 1, 2, 1, 1, 1, 1, 2, 1, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 2, 1}

Here is an alternative way.

Length /@ Join @@ Gather /@ Partition[dex, 3, 1]

{3, 2, 1, 2, 1, 1, 1, 1, 2, 1, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 2, 1}