Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to use regex in a list

# list filtering with regex
import re
l = ['...', 'ram', 'karan','..','......', '....']

pattern = re.compile("..+")
lst = [x for x in l if not re.match(pattern, x)]
print(lst)

# output 
['ram', 'karan']
Comment

PREVIOUS NEXT
Code Example
Python :: how to know the version of python using cmd 
Python :: how to say something python 
Python :: tdmq python 
Python :: python replace accented characters code 
Python :: python unlist flatten nested lists 
Python :: python read parquet 
Python :: Count NaN values of an DataFrame 
Python :: python calculate derivative of function 
Python :: set title matplotlib 
Python :: how to print time python 
Python :: float to percentage python 
Python :: plot.barh() group by 
Python :: normal distribution in python 
Python :: python pair two lists into a dictionary 
Python :: playsound python 
Python :: np confidence interval 
Python :: how to get pygame key 
Python :: mac catallina python3 
Python :: how to detect if the space button is pressed in pygame 
Python :: fixed precision float python 
Python :: pathlib path python 
Python :: basic calculator in python 
Python :: loop through 2 items python 
Python :: pickle load pickle file 
Python :: remove first character from string python 
Python :: draw bounding box on image python opencv 
Python :: list comprehension if else 
Python :: how to use the random module in python 
Python :: how to get a hyperlink in django 
Python :: print groupby dataframe 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =