Replicate and expand a list
For all versions:
Replace[a2, Append[Thread[a -> b], _ -> 0], 1]
{10, 20, 0, 50, 80, 0}
If you need speed look at Dispatch
.
For versions 10.0 or later Association functionality is fast and concise:
Lookup[AssociationThread[a, b], a2, 0]
{10, 20, 0, 50, 80, 0}
Tersely Thread
works in place of AssociationThread
but it causes a redundant evaluation:
Lookup[Thread[a -> b], a2, 0]
{10, 20, 0, 50, 80, 0}
Fold[Insert[#1, 0, #2] &, b, Position[Map[Position[a, #] &, a2], {}]]
{10, 20, 0, 50, 80, 0}
Probably faster with large lists:
Fold[Insert[#1, 0, #2] &, b, Position[a2, Alternatives @@ Complement[a2, a]]]
The most obvious :
If[MemberQ[a, #], b[[Position[a, #][[1, 1]]]], 0] & /@ a2
{10, 20, 0, 50, 80, 0}