Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Let's say I have

Solve[x^4 + 3 == 0, x]

with output

{{x -> -(-3)^(1/4)}, {x -> -i (-3)^(1/4)}, {x ->i (-3)^(1/4)}, {x -> (-3)^(1/4)}}

how do i lose the "x->" part of each string within this list and get something like

{-(-3)^(1/4), -i (-3)^(1/4), i (-3)^(1/4), (-3)^(1/4)}

Thanks for the answers/links. Judging by the answers I realise now that I have formulated my question poorly. I wanted to know how I lose symbols that are in front of a specific symbol. Let's have a look at two more examples:

list={a: horse, b: chicken, c: fish}

how do I lose "a: ","b: ","c: "

or

list2={section 1, section 2, section 3}

how do I lose "section"

share|improve this question
    
Related Q/As: this and this ... –  kguler 2 days ago
    
Thanks for your quick response i have edited my question. –  11drsnuggles11 2 days ago
    
This is the canonical post about how to deal with the list returned by Solve. The other to examples will have to be justified/the context will have to be further explained, I think. –  Pickett 2 days ago
    
öska, my mistake, i've changed it, now it should make more sense ;) –  11drsnuggles11 2 days ago

3 Answers 3

up vote 2 down vote accepted
 lst1 = {{x -> -(-3)^(1/4)}, {x -> -i (-3)^(1/4)}, {x ->  i (-3)^(1/4)},
         {x -> (-3)^(1/4)}};
 lst2 = {a : horse, b : chicken, c : fish};
 lst3 = {section 1, section 2, section 3};
 lst4 = {section1, section2, section3};
 Last @@@ lst1
 (* {-(-3)^(1/4),-(-3)^(1/4) i,(-3)^(1/4) i,(-3)^(1/4)} *)
 Last /@ lst2
 (* {horse,chicken,fish} *)
 Block[{section = 1}, lst3]
 (* {1,2,3} *)
 StringTake[SymbolName/@lst4, -1] 
 (* {1,2,3} *)
 StringReplace[SymbolName /@ lst4, "section" -> ""]
 (* {1,2,3} *)
share|improve this answer

The two cases are different but here is something you can try:

list = {a : horse, b : chicken, c : fish};
list2 = {section 1, section 2, section 3};

list /. x_Pattern :> Last@x
{horse, chicken, fish}
list2 /. section -> 1
{1, 2, 3}
share|improve this answer
    
Your 2nd one is funny because I just was trying: list2 /. section :> Sequence[] which only gives {2, 3} - and I don't know why the 1 is missing :) –  eldo 2 days ago
    
@eldo Because section*1 == section :D –  Öskå 2 days ago

why not simply:

sol = Solve[x^4 + 3 == 0, x]

    x /. sol

or

#[[2]] & @@@ sol

(*{-(-3)^(1/4), -I (-3)^(1/4), I (-3)^(1/4), (-3)^(1/4)}*)

for the second Example you can try:

list = {a : horse, b : chicken, c : fish}
#[[2]] & @@@ Transpose[{list}]
(*{horse, chicken, fish}*)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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