3
$\begingroup$

I am getting this: {{{{{{1, 1}}, {2, 4}}, {3, 9}}, {4, 16}}, {5, 25}}

I want it like this: {{1, 1}, {2, 4}, {3, 9}, {4, 16}, {5, 25}} so that I can use this as coordinate points in ListPlot to make a plot.

I tried using Flatten (it removes all the inner brackets so that it stops being a coordinate) , First etc but nothing worked. Please help

$\endgroup$
2
  • $\begingroup$ Thank you. As of now, using cvgmt's method works perfectly fine. I will check the link out, nonetheless. $\endgroup$ – Lost Sep 23 '20 at 8:59
  • 1
    $\begingroup$ A simple method is to Flatten as you suggested but then to Partition into sublists of 2. This should work: Partition[Flatten[list],2] $\endgroup$ – Hugh Sep 23 '20 at 10:36
6
$\begingroup$
list= {{{{{{1, 1}}, {2, 4}}, {3, 9}}, {4, 16}}, {5, 25}};
Level[list, {-2}]

We can using TreeForm to understand the method.

list= {{{{{{1, 1}}, {2, 4}}, {3, 9}}, {4, 16}}, {5, 25}};
TreeForm[list]

enter image description here

$\endgroup$
2
  • $\begingroup$ Just a note that while this code solves this particular problem, it is not a general solution, since it only works for atomic list elements (numbers in this case). $\endgroup$ – Leonid Shifrin Sep 23 '20 at 7:47
  • $\begingroup$ @LeonidShifrin Thank you,I will go to learn the new method which the link provide. $\endgroup$ – cvgmt Sep 23 '20 at 8:16

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