@Vadim231

Extract как это сделать?

У меня задание: экстрактить строку, как я понял надо убрать пробелы между ними и поставить запятую, как это сделать?
def extract_information(line: str) -> list:
    """
    Extract information from each line (without spaces or extra tabulation symbols).

    Example output: ['Helen-elizabeth', 'IN PANIC', 'Ancient Ruins', None]
    Example output: ['Julianne', 'EATEN', 'Heaven', 'Will rule the kingdom'].
    Obviously, she won't rule anything, however. How sad.
    :param line: decrypted line from the file.
    :return: information about single princess
    """
    print(extract_information("Marni                         FIGHTS FOR LIFE               Old Shack                     Will rule the kingdom"))
    # => ['Marni', 'FIGHTS FOR LIFE', 'Old Shack', 'Will rule the kingdom']
  • Вопрос задан
  • 208 просмотров
Решения вопроса 1
adugin
@adugin Куратор тега Python
Вариант без re:
[phrase.strip() for phrase in text.split('  ') if phrase]
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

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

Войти через центр авторизации
Похожие вопросы