Can this not be handled in python to avoid having to re-index?