-1

This is a scrapping from a selenium scrap dump:

['The Quest for Ethical Artificial Intelligence: A Conversation with 
Timnit Gebru', 'Mindfulness Self-Care for Students of Color', 'GPA: The Geopolitical landscape of the Olympic and Paralympic Movements', 'Interfaith Discussions', 'Mind the Gap', 'First-Year Arts Board Open House', 'Self-Care Night with CARE and BGLTQ+ Specialty Proctors', 'Drawing Plants & Flowers - Sold Out']

I have to pass this to an algorithm but as you can see, although all of them are perfectly encased within quotes, as the sentence breaks after "conversation with" and this is affecting my input. I tried removing whitespaces, didn't work. Any help will be highly appreciated.

Rex
  • 13
  • 2

2 Answers2

0

You can't type a string on multiple lines unless you're using triple quotation marks.

i.e. The first item (string) in your list is

['The Quest for Ethical Artificial Intelligence: A Conversation with 
Timnit Gebru']

You should keep the string on one line as follows.

['The Quest for Ethical Artificial Intelligence: A Conversation with Timnit Gebru']

Or you could use a triple quotation, as I mentioned.

['''The Quest for Ethical Artificial Intelligence: A Conversation with 
Timnit Gebru''']

If you'd like to make your list visible and neat aswell, I'd recommend breaking between commas in the list for example:

['The Quest for Ethical Artificial Intelligence: A Conversation with Timnit Gebru',
'Mindfulness Self-Care for Students of Color', 
'GPA: The Geopolitical landscape of the Olympic and Paralympic Movements', 
'Interfaith Discussions', 
'Mind the Gap',
'First-Year Arts Board Open House', 
'Self-Care Night with CARE and BGLTQ+ Specialty Proctors', 
'Drawing Plants & Flowers - Sold Out']
Pyr0
  • 116
  • 1
  • 8
  • Yeah, you kinda defined my problem for me though. My selenium scraps websites and returns many broken and unbroken strings like that, so I'll have to pass the output directly as the input to another algorithm unless I do some modification at the driver portion, which is what I'm hunting for. Thanks anyway – Rex Mar 04 '22 at 18:20
0

You could try

string_list = ['The Quest for Ethical Artificial Intelligence: A Conversation with 
Timnit Gebru', 'Mindfulness Self-Care for Students of Color', 'GPA: The Geopolitical landscape of the Olympic and Paralympic Movements', 'Interfaith Discussions', 'Mind the Gap', 'First-Year Arts Board Open House', 'Self-Care Night with CARE and BGLTQ+ Specialty Proctors', 'Drawing Plants & Flowers - Sold Out']
string_list = [str.replace("\n", " ") for str in string_list]
  • Oh, I tried that though, but gives me a syntax error ie EOL while scanning string literal, as it breaks at "with" although they have matching quotes. – Rex Mar 04 '22 at 18:12