我有一些以逗号分隔的 python 代码,但不删除空格:
>>> string = "blah, lots , of , spaces, here "
>>> mylist = string.split(',')
>>> print mylist
['blah', ' lots ', ' of ', ' spaces', ' here ']
我宁愿像这样删除空格:
['blah', 'lots', 'of', 'spaces', 'here']
我知道我可以遍历 list 和 strip() 每个项目,但是,因为这是 Python,我猜有一种更快、更简单、更优雅的方法。