The prime minister has pledged to "fight against the extremes in politics on the right and the left" following the election of Green Party's Hannah Spencer.