Using startswith() function inside lists in python

前端 未结 1 1882
-上瘾入骨i
-上瘾入骨i 2021-01-19 04:11

I had the list with following strings below

some_list = [\'9196358485\',\'9966325645\',\'8846853128\',\'8-4-236/2\',\'9-6-32/45\',\'Need to fetch some string         


        
1条回答
  •  醉梦人生
    2021-01-19 04:31

    Use a regular expression:

    >>> import re
    >>> [i for i in some_list if not re.match(r"[98]\B|+\(91\)", i)]
    ['8-4-236/2', '9-6-32/45', 'Need to fetch some strings']
    

    \B matches only within alphanumeric strings, so it matches between 9 and 1 but not between 9 and -.

    0 讨论(0)
提交回复
热议问题