+ 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?
7 ответов
+ 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.
+ 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.
+ 1
HonFu yes, yes, and thanks.
+ 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.
0
It's like 80000 lines, I need the sample size
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
0
Or you could use a file