1

Code :

list = ["\r\n                    Opportunities\r\n                ", "\r\n                    Careers\r\n                ", "\r\n                    Education & training\r\n                ", "\r\n                Find Your Future\r\n ","\r\n\tSanderson        Recruitment, Solutions, Executive, Consulting\r\n"]

Output I want:

["Opportunities","Careers","Education & training","Find Your Future","Sanderson Recruitment, Solutions, Executive, Consulting"]

Since it is a list

1
  • Where did this list come from Commented Mar 8, 2020 at 8:26

2 Answers 2

0

Seems like you want to strip whitespace from your strings. You can apply the strip method to every element of your list using a list comprehension.

mylist = ["\r\n                    Opportunities\r\n                ",
    "\r\n                    Careers\r\n                ",
    "\r\n                    Education & training\r\n                ",
    "\r\n                Find Your Future\r\n ",
    "\r\n\tSanderson        Recruitment, Solutions, Executive, Consulting\r\n"
]

newlist = [s.strip() for s in mylist]
Sign up to request clarification or add additional context in comments.

Comments

0

You can strip surrounding whitespace from strings

out = [x.strip() for x in l] 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.