I want to visualize how Flatten works and have a slider that changes the level of flattening.

Here is the list of lists I'm using and Flatten function.

bifurcate[list_] := Nest[Partition[#, 2] &, list, Floor[Log[2, Length[list1]]]]

(structured = bifurcate[list1])//TreeForm

structured // Flatten[#, n] &

I want to be able to change the value of n from 1 to 3 with a step of 1,


TreeForm[Flatten[structured, n]], {n, 0, 3}

doesn't work. What am I doing wrong?

  • $\begingroup$ Shouldn't bifurcate use Length[list] rather than Length[list1]? $\endgroup$ Feb 22, 2019 at 21:04

1 Answer 1


I think first clean up structured. Then

Manipulate[TreeForm[Flatten[structured, n]], {n, Range[0,3]}]

will give the TreeForm for n in {0,1,2,3}. Just Range[3] for n in {1,2,3}. This is not a "slider" but discrete choices since n is an integer.

  • 4
    $\begingroup$ For a slider, just use {n, 0, 3, 1} instead of {n, Range[0,3]}. $\endgroup$ Feb 22, 2019 at 19:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.