yshihyu 发表于 2014-04-15 21:59

libo26_lee 发表于 2014-04-15 23:02

试试b = a.split(' +')

yshihyu 发表于 2014-04-15 23:27

to407 发表于 2014-04-16 07:53

>>> import re

>>> re.split("\s+","a\tbc d   e")
['a', 'b', 'c', 'd', 'e']



icymirror 发表于 2014-04-16 09:56

回复 1# yshihyu
可以这样:

In : c = filter( lambda item: len(item) > 0, b)

In : c
Out: ['hello', 'sss', 'c']

ragkk 发表于 2014-04-16 10:16

想的太复杂了


直接a=split()


就可以了

yshihyu 发表于 2014-04-16 10:56

修杰_JIANG 发表于 2014-04-16 11:08

本帖最后由 修杰_JIANG 于 2014-04-16 11:10 编辑

ssfjhh 发表于 2014-04-16 13:06

回复 8# 修杰_JIANG


      

timespace 发表于 2014-04-16 13:32

童鞋们写代码不自测吗?很平常的一个需求,不用那么多花样吧:em16:>>> 'hello   sss   c'.split()
['hello', 'sss', 'c']
>>>
页: [1] 2
查看完整版本: string split 处理