键值对 取值

 

                    # l=['推荐 252阅读 14评论 0涨粉 0转发 0收藏 0']
                    for i in range(len(s) - 1):
                        sub_ = s[i:i + 1]
                        try:
                            t = int(sub_)
                        except Exception as e:
                            s = s.replace(sub_, 'X')
                            print(e)
                    v_l = s.replace('XX', '').split('X')[1:]
                    s = '推荐 252阅读 14评论 0涨粉 0转发 0收藏 0'
                    # 3.5万
                    # l=['推荐 252阅读 14评论 0涨粉 0转发 0收藏 0']
                    for i in range(len(s) - 1):
                        sub_ = s[i:i + 1]
                        try:
                            t = int(sub_)
                            s = s.replace(sub_, 'X')
                        except Exception as e:
                            print(e)
                    k_l = s.replace('XX', 'X').replace('XX', 'X').split('X')[:-1]

 是数字的仅且仅为目标字符

将不是数字的字符替换,然后切割字符串

 

posted @ 2018-05-31 10:55  papering  阅读(615)  评论(0编辑  收藏  举报