str.(r)partition: factor our duplicate code.

Switch str.rpartition to search from left to right. Factor the
duplicate code into one helper function.