allexj allexj - 2 months ago 5
Python Question

Delete spaces from items in a list

I have this list:

input_list = ["1.2.3.4", " 2.3.4.5", " 3.4.5.6"]


And I'd like to remove that space in the second e third words... How can I do?

I tried with:

for x in input_list:
x.strip(" ")


and with:

for x in input_list:
x.replace(" ","")

Answer
your_list = [element.strip() for element in your_list]
Comments