I have a list that looks like this:
['\r1/19/2015', '1/25/2015\r']
I got this data from the web, and it just started coming with the \r today. This causes an error in my script, so I am wondering how to remove the \r from the list.
You can use str.strip. '\r' is a carriage return, and strip removes leading and trailing whitespace and new line characters.
>>> l = ['\r1/19/2015', '1/25/2015\r']
>>> l = [i.strip() for i in l]
>>> l
['1/19/2015', '1/25/2015']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With