improve python snippet