@ivanburdin

Как получить список из элементов типа string?

Есть объект, который содержит список ошибок, необходимо получить список, что бы его каждый элемент был типа string, при этом пробельные символы в конце строки необходимо обрезать. На примере ниже получилось частично это реализовать, но не знаю как грамотно обрезать через strip пробельные символы, используя эту конструкцию. Буду рад увидеть альтернативные видения решения этого вопроса =)

validator.iter_errors(js)
<generator object create.<locals>.Validator.iter_errors at 0x7f8d640c2e08>
errors = list(map(str, validator.iter_errors(js)))
errors
["5 is not of type 'string'\n\nFailed validating 'type' in schema['properties']['result']['items']['properties']['complainant']['items']['properties']['complainantAddress']['properties']['floor']:\n    {'type': 'string'}\n\nOn instance['result'][0]['complainant'][0]['complainantAddress']['floor']:\n    5", "4 is not of type 'string'\n\nFailed validating 'type' in schema['properties']['result']['items']['properties']['complainant']['items']['properties']['complainantAddress']['properties']['entrance']:\n    {'type': 'string'}\n\nOn instance['result'][0]['complainant'][0]['complainantAddress']['entrance']:\n    4", "55.764891 is not of type 'string'\n\nFailed validating 'type' in schema['properties']['result']['items']['properties']['complainant']['items']['properties']['complainantAddress']['properties']['addressGeoLatitude']:\n    {'type': 'string'}\n\nOn instance['result'][0]['complainant'][0]['complainantAddress']['addressGeoLatitude']:\n    55.764891", "37.659497 is not of type 'string'\n\nFailed validating 'type' in schema['properties']['result']['items']['properties']['complainant']['items']['properties']['complainantAddress']['properties']['addressGeoLongitude']:\n    {'type': 'string'}\n\nOn instance['result'][0]['complainant'][0]['complainantAddress']['addressGeoLongitude']:\n    37.659497", "55.769018 is not of type 'string'\n\nFailed validating 'type' in schema['properties']['result']['items']['properties']['complainant']['items']['properties']['complainantAddress']['properties']['phoneGeoLatitude']:\n    {'type': 'string'}\n\nOn instance['result'][0]['complainant'][0]['complainantAddress']['phoneGeoLatitude']:\n    55.769018", "37.657188 is not of type 'string'\n\nFailed validating 'type' in schema['properties']['result']['items']['properties']['complainant']['items']['properties']['complainantAddress']['properties']['phoneGeoLongtitude']:\n    {'type': 'string'}\n\nOn instance['result'][0]['complainant'][0]['complainantAddress']['phoneGeoLongtitude']:\n    37.657188", "55.774062 is not of type 'string'\n\nFailed validating 'type' in schema['properties']['result']['items']['properties']['eventAddress']['properties']['addressGeoLatitude']:\n    {'type': 'string'}\n\nOn instance['result'][0]['eventAddress']['addressGeoLatitude']:\n    55.774062", "37.756964 is not of type 'string'\n\nFailed validating 'type' in schema['properties']['result']['items']['properties']['eventAddress']['properties']['addressGeoLongitude']:\n    {'type': 'string'}\n\nOn instance['result'][0]['eventAddress']['addressGeoLongitude']:\n    37.756964", "'830' is not of type 'integer'\n\nFailed validating 'type' in schema['properties']['result']['items']['properties']['vehicle']['items']['properties']['vehicleId']:\n    {'type': 'integer'}\n\nOn instance['result'][0]['vehicle'][0]['vehicleId']:\n    '830'", "'830' is not of type 'integer'\n\nFailed validating 'type' in schema['properties']['result']['items']['properties']['vehicle']['items']['properties']['vehicleId']:\n    {'type': 'integer'}\n\nOn instance['result'][0]['vehicle'][1]['vehicleId']:\n    '830'", "'830' is not of type 'integer'\n\nFailed validating 'type' in schema['properties']['result']['items']['properties']['vehicle']['items']['properties']['vehicleId']:\n    {'type': 'integer'}\n\nOn instance['result'][0]['vehicle'][2]
  • Вопрос задан
  • 108 просмотров
Пригласить эксперта
Ответы на вопрос 2
Комментировать
@artem78
errors = list(map(str.strip, map(str, validator.iter_errors(js))))

Если нужно удалять пробелы только в конце, вместо strip используйте rstrip.
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы