在 Python 中用逗號分隔並去除空格

| | | | | | |

我有一些用逗號分隔的 python 代碼,但沒有去掉空格:

>>> string = "blah, lots, of , spaces, here " >>> mylist = string.split(",") >>> print mylist ["blah", "lots", "of", "spaces", "here"] 

我寧願像這樣刪除空格:

["blah", "lots", "of", "spaces", "here"] 

代碼>

我知道我可以循環遍歷列表並 strip() 每個項目,但由於這是 Python,我猜這是一種更快、更簡單、更優雅的方式。