Blogger Information
Blog 75
fans 0
comment 0
visits 54680
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
小猿圈python之字符串多个分隔符截取
聆听的博客
Original
579 people have browsed it

学习python的同学们都知道,字符串这个基本的数据类型是重中之重,不管做什么都会用到,就和咱们的拼音字母似的,小猿圈今天教大家一个小小的技巧,python中字符串多个分隔符怎么截取,一起看一下吧。

实例

#!/bin/python
import re
s='aa,bb:cc;dd/teegg'
def mysplit(s,symbol):
    t=[s]
    for num in symbol:
        res=[]
        map(lambda x:res.extend(x.split(num)),t)
        t=res
    return [x for x in res if x]

print mysplit(s,r',:;/t<>')
print re.split(r'[,:;/t<>]+',s)

运行实例 »

点击 "运行实例" 按钮查看在线实例

是不是感觉很简单呢?不过实用是真的,小猿圈教大家又学习了一招,大家一定要好好把每天get到的点记录总结下来,可以写个博客啊,以后用的时候拿出来可以直接用,不然会书到用时方恨少,加油吧。

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!