If you want to remove \n
from the last element only, use this:
t[-1] = t[-1].strip()
If you want to remove \n
from all the elements, use this:
t = map(lambda s: s.strip(), t)
You might also consider removing \n
before splitting the line:
line = line.strip()
# split line...
More Related Contents:
- Writing a list to a file with Python
- Writing a list to a file with Python, with newlines
- I have a list of file names and I need to be able to count how many of the same file gets repeated for each file name [closed]
- How do I check if a list is empty?
- What’s the difference between lists and tuples?
- How to remove list elements in a for loop in Python? [duplicate]
- Iterate over all pairs of consecutive items in a list [duplicate]
- How Big can a Python List Get?
- Python recursion with list returns None [duplicate]
- Why is a list comprehension so much faster than appending to a list?
- Converting a String to a List of Words?
- Create a list with initial capacity in Python
- How to perform element-wise multiplication of two lists?
- elegant find sub-list in list
- How to group a list of tuples/objects by similar index/attribute in python?
- How to force a list to a fixed size?
- Pandas expand rows from list data available in column
- How to check if an object is a list or tuple (but not string)?
- How to remove all duplicate items from a list [duplicate]
- Unpack list to variables
- Python using enumerate inside list comprehension
- How to find common elements in list of lists?
- How to convert a string list into an integer in python [duplicate]
- Convert list of strings to dictionary
- Most efficient way for a lookup/search in a huge list (python)
- How to make a completely unshared copy of a complicated list? (Deep copy is not enough)
- How can I use newline ‘\n’ in an f-string to format output?
- How can I partition (split up, divide) a list based on a condition?
- Python: Rename duplicates in list with progressive numbers without sorting list
- Nested lambda statements when sorting lists