我有一些在逗号处分割的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,所以我猜有一种更快,更轻松和更优雅的方法。
浮云间
相关分类