5
$\begingroup$

I have a list of the form:

{
 {0.185794, {α -> 5.8794,  χ -> 3.14159}}
,{0.206365, {α -> 6.07943, χ -> 3.14159}}
}

How can I transform this list such that it contains triplets of the form:

{5.8794, 3.14159 }

That is, I want to drop the first element and retain the next two elements without the variables.

Edit:

The complete list is:

  list = {{0.`, {α -> 7.40402817067928`*^-10, χ -> 
  1.5707963199759551`}}, {-1.1102230246251565`*^-16, {α -> 
  0.`, χ -> 
  1.570796310785471`}}, {-1.3322676295501878`*^-15, {α -> 
  6.283185236232465`, χ -> 
  1.5707962926795942`}}, {-7.771561172376096`*^-16, {α -> 
  6.283185242937872`, χ -> 
  1.5707962817101633`}}, {-1.4432899320127035`*^-15, {α -> 
  6.283185213845592`, χ -> 
  1.5707962574691037`}}, {-1.6653345369377348`*^-15, {α -> 
  6.283185168970566`, χ -> 
  1.5707962135597096`}}, {0.000039743185786034196`, {α -> 
  6.101378684908873`, χ -> 
  1.416341223365662`}}, {0.04502974573215446`, {α -> 
  4.8669662247178715`, χ -> 
  0.8684522135648123`}}, {0.14619238131191453`, {α -> 
  3.9372113567750526`, χ -> 
  1.0267300878173935`}}, {-0.03365091466576414`, {α -> 
  6.283185307179586`, χ -> 
  3.141592653589793`}}, {0.0387037789988178`, {α -> 
  5.27985616378398`, χ -> 
  3.141592653589793`}}, {0.5500615962645923`, {α -> 
  3.14159261319097`, χ -> 
  1.5707963347517426`}}, {0.1502504642607271`, {α -> 
  5.679720812825692`, χ -> 
  3.141592653589793`}}, {0.18579431483854147`, {α -> 
  5.8793987995998735`, χ -> 
  3.141592653589793`}}, {0.20636475575559726`, {α -> 
  6.07942545836383`, χ -> 
  3.141592653589793`}}, {0.2116046084330751`, {α -> 
  6.279301995689666`, χ -> 
  3.141592653589793`}}, {0.20176755574756772`, {α -> 
  0.08350912308643653`, χ -> 
  3.941791666553896`*^-9}}, {0.1776933003532231`, {α -> 
  0.08350912308643653`, χ -> 
  3.941791666553896`*^-9}}, {0.6036070488425198`, {α -> 
  3.1415926143838626`, χ -> 
  1.5707962914138776`}}, {0.5018188905655654`, {α -> 
  3.141592611777223`, χ -> 1.5707963036550594`}}};
$\endgroup$
9
$\begingroup$
{\[Alpha], \[Chi]} /. list[[All, 2]]

or

list[[All, 2, All, 2]]

If list is very huge, the second method has much higher efficiency.

$\endgroup$
  • $\begingroup$ This is the best answer, I think, just using Part. $\endgroup$ – Emilio Pisanty Jul 24 '16 at 0:34
7
$\begingroup$
list = {{0.185794, {α -> 5.8794, χ -> 3.14159}},
   {0.206365, {α -> 6.07943, χ -> 3.14159}}};

{#2[[1, 2]], #2[[2, 2]]} & @@@ list

{{5.8794, 3.14159}, {6.07943, 3.14159}}

Also

Last /@ Last[#] & /@ list

and

Extract[list, {All, 2, {1, 2}, 2}]
$\endgroup$
  • $\begingroup$ What if I had a huge list? What would be the syntax then? $\endgroup$ – Junaid Aftab Jul 23 '16 at 11:14
  • $\begingroup$ I'll post the complete list in the question. $\endgroup$ – Junaid Aftab Jul 23 '16 at 11:14
  • $\begingroup$ It would work for all the sublists. $\endgroup$ – Chris Degnen Jul 23 '16 at 11:17
  • $\begingroup$ Awesome. Can you send me the link to the documentation where I can read more on this? I tried searching multiple times for a solution to this option but to no avail. $\endgroup$ – Junaid Aftab Jul 23 '16 at 11:19
  • $\begingroup$ Apply, Slot, Map and Pure Functions. $\endgroup$ – Chris Degnen Jul 23 '16 at 11:24
5
$\begingroup$

Cases[list, {_, {a_ -> x_, b_ -> y_}} :> {x, y}]

$\endgroup$
  • $\begingroup$ Also: list /. { _, {α ->x_ , χ ->y_}} -> {x, y} should work. There is no need for a delayed rule here, I believe (I'm writing this in the blind). $\endgroup$ – Peltio Jul 24 '16 at 10:54
4
$\begingroup$

You may use Last, Values, and Composition.

Values@*Last /@ list

Hope this helps.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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