Fix invalid iterator error under python3.