python handle indexerror list index out of range