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

eyllanesc
  • 221,139
  • 17
  • 121
  • 189
Subu
  • 13
  • 2

2 Answers2

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]
khelwood
  • 52,115
  • 13
  • 74
  • 94
0

You can strip surrounding whitespace from strings

out = [x.strip() for x in l] 
OneCricketeer
  • 151,199
  • 17
  • 111
  • 216