1

I have a python array containing a mixed set of values that looks somewhat like the example below:

['0012 ', ' 318422 ', ' www.example.com']

My question is, how can I easily remove leading and trailing spaces from values in the array, such that it looks like this:

['0012', '318422', 'www.example.com']
0

2 Answers 2

6

Like so

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

Comments

0

You can use map and strip:

a = ['0012 ', ' 318422 ', ' www.example.com']
clean_a = map(lambda x: x.strip(), a)

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.