1
$\begingroup$

I have a list, which consists of several nested lists, and I want to extract first elements in each of this nested list and put as one single list. how to do this?

   {{{b->4.72971}},{{b->4.76615}},{{b->1.91842},{b->4.80339}},{{b->1.93338},{b->4.84177}},{{b->1.94861},{b->4.88068}},{{b->1.96412},{b->4.92126}},{{b->1.97992},{b->4.96216}},{{b->1.99601}},{{b->2.01241}},{{b->2.02913}},{{b->2.04617}},{{b->2.06355}},{{b->2.08127}},{{b->2.09935}},{{b->2.1178}},{{b->2.13663}},{{b->2.15585}},{{b->2.17548}},{{b->2.19553}},{{b->2.21601}},{{b->2.23694}},{{b->2.25834}},{{b->2.28021}},{{b->2.30259}},{{b->2.32548}},{{b->2.34891}},{{b->2.37289}},{{b->2.39745}},{{b->2.4226}},{{b->2.44837}},{{b->2.47479}},{{b->2.50188}},{{b->2.52967}},{{b->2.55817}},{{b->2.58743}},{{b->2.61748}},{{b->2.64833}},{{b->2.68004}},{{b->2.71264}},{{b->2.74615}},{{b->2.78063}},{{b->2.8161}},{{b->2.85263}},{{b->2.89024}},{{b->2.92899}},{{b->2.96893}},{{b->3.0101}},{{b->3.05257}},{{b->3.09638}},{{b->3.14159}},{{b->3.18826}},{{b->3.23645}},{{b->3.28622}},{{b->3.33762}},{{b->3.39071}},{{b->3.44554}},{{b->3.50216}},{{b->3.5606}},{{b->3.62089}},{{b->3.68304}},{{b->3.74702}},{{b->3.81279}},{{b->3.88026}},{{b->3.94925}},{{b->4.01955}},{{b->4.09082}},{{b->4.16259}},{{b->4.23424}},{{b->4.30495}},{{b->4.3737}},{{b->4.43922}},{{b->4.50009}},{{b->4.55476}},{{b->4.6017}},{{b->4.63965}},{{b->4.66773}},{{b->4.68562}},{{b->4.69355}},{{b->4.69221}},{{b->4.68259}},{{b->4.66581}},{{b->4.64302}},{{b->4.61527}},{{b->4.58351}},{{b->4.54857}},{{b->4.51112}},{{b->4.47174}},{{b->4.43093}},{{b->4.38908}},{{b->4.34653}},{{b->4.30356}},{{b->4.2604}},{{b->4.21725}},{{b->4.17428}},{{b->4.13163}},{{b->4.08941}},{{b->4.04772}},{{b->4.00664}},{{b->3.96625}},{{b->3.9266}}}
$\endgroup$
2
  • 4
    $\begingroup$ Maybe something like list[[All, 1]], list[[All, All, 1]], or list[[All, All, All, 1]] does what you want. I cannot tell because you did not give any example for desired output... $\endgroup$ Commented Jan 30, 2019 at 16:01
  • $\begingroup$ If u look at the third root it has value 1.91842 and 4.80339 , I want to read only 1.91842 $\endgroup$
    – acoustics
    Commented Jan 30, 2019 at 16:12

1 Answer 1

2
$\begingroup$

Is this ok?

list = {{{b -> 4.72971}}, {{b -> 4.76615}}, {{b -> 1.91842}, {b -> 
      4.80339}}, {{b -> 1.93338}, {b -> 4.84177}}, {{b -> 
      1.94861}, {b -> 4.88068}}, {{b -> 1.96412}, {b -> 
      4.92126}}, {{b -> 1.97992}, {b -> 4.96216}}, {{b -> 
      1.99601}}, {{b -> 2.01241}}, {{b -> 2.02913}}, {{b -> 
      2.04617}}, {{b -> 2.06355}}, {{b -> 2.08127}}, {{b -> 
      2.09935}}, {{b -> 2.1178}}, {{b -> 2.13663}}, {{b -> 
      2.15585}}, {{b -> 2.17548}}, {{b -> 2.19553}}, {{b -> 
      2.21601}}, {{b -> 2.23694}}, {{b -> 2.25834}}, {{b -> 
      2.28021}}, {{b -> 2.30259}}, {{b -> 2.32548}}, {{b -> 
      2.34891}}, {{b -> 2.37289}}, {{b -> 2.39745}}, {{b -> 
      2.4226}}, {{b -> 2.44837}}, {{b -> 2.47479}}, {{b -> 
      2.50188}}, {{b -> 2.52967}}, {{b -> 2.55817}}, {{b -> 
      2.58743}}, {{b -> 2.61748}}, {{b -> 2.64833}}, {{b -> 
      2.68004}}, {{b -> 2.71264}}, {{b -> 2.74615}}, {{b -> 
      2.78063}}, {{b -> 2.8161}}, {{b -> 2.85263}}, {{b -> 
      2.89024}}, {{b -> 2.92899}}, {{b -> 2.96893}}, {{b -> 
      3.0101}}, {{b -> 3.05257}}, {{b -> 3.09638}}, {{b -> 
      3.14159}}, {{b -> 3.18826}}, {{b -> 3.23645}}, {{b -> 
      3.28622}}, {{b -> 3.33762}}, {{b -> 3.39071}}, {{b -> 
      3.44554}}, {{b -> 3.50216}}, {{b -> 3.5606}}, {{b -> 
      3.62089}}, {{b -> 3.68304}}, {{b -> 3.74702}}, {{b -> 
      3.81279}}, {{b -> 3.88026}}, {{b -> 3.94925}}, {{b -> 
      4.01955}}, {{b -> 4.09082}}, {{b -> 4.16259}}, {{b -> 
      4.23424}}, {{b -> 4.30495}}, {{b -> 4.3737}}, {{b -> 
      4.43922}}, {{b -> 4.50009}}, {{b -> 4.55476}}, {{b -> 
      4.6017}}, {{b -> 4.63965}}, {{b -> 4.66773}}, {{b -> 
      4.68562}}, {{b -> 4.69355}}, {{b -> 4.69221}}, {{b -> 
      4.68259}}, {{b -> 4.66581}}, {{b -> 4.64302}}, {{b -> 
      4.61527}}, {{b -> 4.58351}}, {{b -> 4.54857}}, {{b -> 
      4.51112}}, {{b -> 4.47174}}, {{b -> 4.43093}}, {{b -> 
      4.38908}}, {{b -> 4.34653}}, {{b -> 4.30356}}, {{b -> 
      4.2604}}, {{b -> 4.21725}}, {{b -> 4.17428}}, {{b -> 
      4.13163}}, {{b -> 4.08941}}, {{b -> 4.04772}}, {{b -> 
      4.00664}}, {{b -> 3.96625}}, {{b -> 3.9266}}};

Cases[First /@ list, {x_} -> x]//TeXForm

$\small{\{b\to 4.72971,b\to 4.76615,b\to 1.91842,b\to 1.93338,b\to 1.94861,b\to 1.96412,b\to 1.97992,b\to 1.99601,b\to 2.01241,b\to 2.02913,b\to 2.04617,b\to 2.06355,b\to 2.08127,b\to 2.09935,b\to 2.1178,b\to 2.13663,b\to 2.15585,b\to 2.17548,b\to 2.19553,b\to 2.21601,b\to 2.23694,b\to 2.25834,b\to 2.28021,b\to 2.30259,b\to 2.32548,b\to 2.34891,b\to 2.37289,b\to 2.39745,b\to 2.4226,b\to 2.44837,b\to 2.47479,b\to 2.50188,b\to 2.52967,b\to 2.55817,b\to 2.58743,b\to 2.61748,b\to 2.64833,b\to 2.68004,b\to 2.71264,b\to 2.74615,b\to 2.78063,b\to 2.8161,b\to 2.85263,b\to 2.89024,b\to 2.92899,b\to 2.96893,b\to 3.0101,b\to 3.05257,b\to 3.09638,b\to 3.14159,b\to 3.18826,b\to 3.23645,b\to 3.28622,b\to 3.33762,b\to 3.39071,b\to 3.44554,b\to 3.50216,b\to 3.5606,b\to 3.62089,b\to 3.68304,b\to 3.74702,b\to 3.81279,b\to 3.88026,b\to 3.94925,b\to 4.01955,b\to 4.09082,b\to 4.16259,b\to 4.23424,b\to 4.30495,b\to 4.3737,b\to 4.43922,b\to 4.50009,b\to 4.55476,b\to 4.6017,b\to 4.63965,b\to 4.66773,b\to 4.68562,b\to 4.69355,b\to 4.69221,b\to 4.68259,b\to 4.66581,b\to 4.64302,b\to 4.61527,b\to 4.58351,b\to 4.54857,b\to 4.51112,b\to 4.47174,b\to 4.43093,b\to 4.38908,b\to 4.34653,b\to 4.30356,b\to 4.2604,b\to 4.21725,b\to 4.17428,b\to 4.13163,b\to 4.08941,b\to 4.04772,b\to 4.00664,b\to 3.96625,b\to 3.9266\}}$

$\endgroup$
8
  • $\begingroup$ The piece of code that you suggested is not giving me right result $\endgroup$
    – acoustics
    Commented Jan 30, 2019 at 16:28
  • 1
    $\begingroup$ @acoustics First /@ list ? $\endgroup$
    – Jerry
    Commented Jan 30, 2019 at 16:31
  • $\begingroup$ its working, thanks. If I put Second instead of first will it read the second element? $\endgroup$
    – acoustics
    Commented Jan 30, 2019 at 16:36
  • 1
    $\begingroup$ @acoustics you're welcome :) try Cases[Last /@ list, {x_} -> x] $\endgroup$
    – Jerry
    Commented Jan 30, 2019 at 16:38
  • $\begingroup$ Got it , I have been using mathematica from past 8 months, still lot of things to learn. Thanks alot @jerry $\endgroup$
    – acoustics
    Commented Jan 30, 2019 at 16:42

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.