1

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"

Verbeia
  • 34,233
  • 9
  • 109
  • 224
11drsnuggles11
  • 363
  • 1
  • 11

3 Answers3

3

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}
Öskå
  • 8,587
  • 4
  • 30
  • 49
  • 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 Aug 10 '14 at 18:39
  • @eldo Because section*1 == section :D – Öskå Aug 10 '14 at 19:05
2
 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} *)
kglr
  • 394,356
  • 18
  • 477
  • 896
1

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}*)
Basheer Algohi
  • 19,917
  • 1
  • 31
  • 78