Replace elements according indexes

found this:

Do you know another way?