开发者

To split on the basis of space and special character in python

v=开发者_运维百科vi nod-u

i want to split this string to obtain

l=[vi],[nod],[u]

l.split(" ") splits on the basis of space.

And i dont know the usage of the regular expression import functions properly. Could anyone explain how to do that?


Are you trying to split the string to get words? If so, try the following:

>>> import re
>>> pattern = re.compile(r'\W+')
>>> pattern.split('vi nod-u')
['vi', 'nod', 'u']
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜