Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove \r from list [duplicate]

Tags:

python

list

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.

like image 662
iqueqiorio Avatar asked Apr 08 '26 02:04

iqueqiorio


1 Answers

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']
like image 153
Cory Kramer Avatar answered Apr 09 '26 14:04

Cory Kramer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!