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

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