How to make a substitution that involves a nested list? [closed]

I need to make a substitution for the variable xxx from this.

sub = {{x -> 2}, {x -> 5}}

I want to give to xxx one of these two values, say 222. If I write

a)a) x = sub [[1]][[1]][[2]]

then it works but if I use instead

b)b) x = sub [[1]]

or

c)c) x = sub [[1]][[2]]

it doesn’t and it crashes.

Is sub to be considered a nested list? If so, it is not clear the reason why b)b) or c)c) do not work, since if I need the first sublist of a nested list I simply write list[[1]], right?

Where is my mistake?

Thanks for your help

=================

=================

1 Answer
1

=================

So what was needed, if you wanted to go down that path, was sub[[1,1,2]] but the following is better:

x /. sub[[1]]

(* 2 *)