@hardwellZero

Как почистить list?

Добрый вечер.
Выпарсиваю с небольшой статью заголовки, на выходе получаю list вот такого вида:
['\nSave rainforests or they will worsen climate change, warns ex-WWF chief ', 
' \n$10m a minute given to fossil fuel companies in government subsidies ', 
' \n\xc2\xa0\n\nFossil fuel giants reject calls to keep oil, gas and coal in ground ',
 "\xc2\xa0\nSaudi oil minister: 'Fossil fuels doomed, we're switching to solar' ", 
' \nCoal and solar power executives clash at Paris climate conference ',
 ' \nUK cities should generate their own energy, National Trust says ', 
' \nCalifornia investigates nine-mile oil slick ', ' \nOxford Uni to stay away from oil and coal investments ',
 " \n\xc2\xa0\n\nGap between rich and poor 'keeps growing' ", 
' \nOil shock could push UK into deeper deflation, warns Bank of England ',
 " \nMcDonald's boss 'proud' of wages as thousands demand a pay rise ",
 ' \n\xc2\xa0\n\nFrance to force big supermarkets to give away unsold food to charity ', 
' \nTesco to cut soft drinks sugar content ', ' \nSugar tax to pay for treating obesity ',
 " \n\xc2\xa0\n\nAntarctic Peninsula in 'dramatic' ice loss ",
 ' \nVideo: Great Barrier Reef under the spotlight for World Turtle Day ', 
" \nHow 'upcycling' became the hot new craft industry ", 
' \nA grassroots effort to save Africa\xe2\x80\x99s most endangered ape ', 
' \n\xc2\xa0\n\n\nGreenhouse Pioneer: Canon Christopher Hall, Pension Activist ']

Можно как-то убрать оттуда все \n\xc2\xa0 и другой мусор?
  • Вопрос задан
  • 324 просмотра
Решения вопроса 2
daapp
@daapp
Программист
Модуль re есть, для тех кто продвинут. Для остальных str.replace.
Ответ написан
@to_climb
Вот это вот похоже на проблему с кодировкой: «\xe2\x80\x99».
Похоже, статья в utf-8, а кодировка чтения другая.

\n в начале и конце строки убираются с помощью str.[r|l|]strip('\n')
Ответ написан
Комментировать
Пригласить эксперта
Ответы на вопрос 1
sim3x
@sim3x
не надо там ничего ичстить
l = ['\nSave rainforests or they will worsen climate change, warns ex-WWF chief ', 
   ...: ' \n$10m a minute given to fossil fuel companies in government subsidies ', ]

In [2]: ' || '.join(l)
Out[2]: '\nSave rainforests or they will worsen climate change, warns ex-WWF chief  ||  \n$10m a minute given to fossil fuel companies in government subsidies '

In [3]: print ' || '.join(l)

Save rainforests or they will worsen climate change, warns ex-WWF chief  ||  
$10m a minute given to fossil fuel companies in government subsidies 

In [4]:
Ответ написан
Комментировать
Ваш ответ на вопрос

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

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