how to remove newlines from imported lists when i cant work with it yet | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

how to remove newlines from imported lists when i cant work with it yet

i copy and pasted a list and cant use it as a string or list because it thinks i have empty quotes, eol errors. is there any quick fix to remove thousands of enters so i can work with it and get what i need? or is there a long route i have to take by importing the file?

13th Jun 2023, 6:33 AM
Travis Beard
Travis Beard - avatar
7 Answers
+ 6
I'm not exactly getting what your problem is. I imagine that you found some list of words or numbers somewhere on the web, but when you use it in your code, you get errors? Maybe the triple quotation mark pattern can solve your problem. yourVariable = """ copypaste your stuff here """ After that, you should have that list as a string and can then work to sanitize it, by erasing punctuation you have no use for or whatever.
13th Jun 2023, 7:02 AM
HonFu
HonFu - avatar
+ 5
Save the list by right-click context menu option; if you copy-paste it, there is a chance that you miss some characters. If it is stored in a table-like format, consider reading the file with a pandas function – that should handle a lot of things and gives you a useful data structure to work with.
13th Jun 2023, 8:46 AM
Lisa
Lisa - avatar
+ 1
HonFu yes, yes, and thanks.
13th Jun 2023, 7:06 AM
Travis Beard
Travis Beard - avatar
+ 1
Travis Beard maybe you could post a partial snippet of the copied data so that members here could help you develop a data sanitation strategy.
13th Jun 2023, 9:14 AM
Bob_Li
Bob_Li - avatar
0
It's like 80000 lines, I need the sample size
13th Jun 2023, 7:02 AM
Travis Beard
Travis Beard - avatar
0
You could trasform list in string throught this: list=[cheese,love] delimitation="" list=delimitation.join(list) And After puts methods of string list= list.strip() print(list) If works, answer me
14th Jun 2023, 7:13 AM
Glo
0
Or you could use a file
14th Jun 2023, 7:15 AM
Glo