使用列表理解-更简单,就像
for循环一样容易阅读。
my_string = "blah, lots , of , spaces, here "result = [x.strip() for x in my_string.split(',')]# result is ["blah", "lots", "of", "spaces", "here"]请参阅:
有关列表理解的Python文档
很好的2秒钟的列表理解说明。

使用列表理解-更简单,就像
for循环一样容易阅读。
my_string = "blah, lots , of , spaces, here "result = [x.strip() for x in my_string.split(',')]# result is ["blah", "lots", "of", "spaces", "here"]请参阅:
有关列表理解的Python文档
很好的2秒钟的列表理解说明。