@ilyakmet

Как грамотно разложить сплитом строку?

Есть строка '40920 8.326976 0.953952 largeDoses'. Не везде одинаковое кол-во пробелов. Нужно сделать нормальный список. Есть ли простое решение со split() ?
  • Вопрос задан
  • 408 просмотров
Решения вопроса 1
Если я правильно вас понял, то вам подойдёт обычный сплит
https://docs.python.org/3.4/library/stdtypes.html#...
https://docs.python.org/2/library/stdtypes.html#st...
'40920 8.326976 0.953952 largeDoses'.split()
If sep is not specified or is None, a different splitting algorithm is applied: runs of consecutive whitespace are regarded as a single separator, and the result will contain no empty strings at the start or end if the string has leading or trailing whitespace. Consequently, splitting an empty string or a string consisting of just whitespace with a None separator returns [].
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

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

Войти через центр авторизации
Похожие вопросы
01 мая 2024, в 22:47
30000 руб./за проект
01 мая 2024, в 22:26
10000 руб./за проект