You need to access the element that you want to strip from the list:
line= ['ABDFDSFGSGA', '32\n']
#We want to strip all elements in this list
stripped_line = [s.rstrip() for s in line]
What you might have done wrong, is to simply call line[1].rstrip()
. This won't work, since the rstrip
method does not work inplace, but returns a new string which is stripped.
Example:
>>> a = 'mystring\n'
>>> a.rstrip()
Out[22]: 'mystring'
>>> a
Out[23]: 'mystring\n'
>>> b = a.rstrip()
>>> b
Out[25]: 'mystring'