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
  • 235,170
  • 19
  • 170
  • 241
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
  • 55,782
  • 14
  • 81
  • 108
0

You can strip surrounding whitespace from strings

out = [x.strip() for x in l] 
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245