Is there a better way to use strip() on a list of strings? - python [duplicate]
问题 This question already has answers here : Remove trailing newline from the elements of a string list (7 answers) Closed 3 years ago . For now i've been trying to perform strip() on a list of strings and i did this: i = 0 for j in alist: alist[i] = j.strip() i+=1 Is there a better way of doing that? 回答1: You probably shouldn't be using list as a variable name since it's a type. Regardless: list = map(str.strip, list) This will apply the function str.strip to every element in list , return a new