This is not what Rules
are made for but the following works well for simple cases:
solution[[All, 2]]
{1, 10, 100}
More "proper" way:
a /@ Range[3] /. solution
or equivalent suggested by Mr. Wizard
Array[a, 3] /. solution
For more nested list of rules you can use Cases
(but then you have to keep an eye on what is what ;)) :
Cases[solution, HoldPattern[a[_](a[_] -> x_] x_):> x, Infinity]
{1, 10, 100}
Or the same but in different form:
Cases[solution, Rule[a[_], x_] :> x, Infinity]
Cases[solution, (a[_]HoldPattern[a[_] -> x_)x_] :> x, Infinity]
Remarks about Cases
:
- For your example, default levelspec for
Cases
, which is{1}
, will do the job. ReplaceAll
(/.
) will work withsolution
containingRule
(->
) orRuleDelayed
(:>
) but forCases
we have to point this out:
solution = {a[1] -> 1, a[2] :> 5, a[3] -> 100}
Cases[solution, Rule[a[_], x_] :> x]
Cases[solution, (Rule | RuleDelayed)[a[_], x_] :> x]
{a[1] -> 1, a[2] :> 5, a[3] -> 100} {1, 100} {1, 5, 100}