Implements 'substitution' function for lists.