import re
pattern = re.compile(some_regular_expression)
some_text = re.sub(pattern, '', data)
import time
itemlist = [23, 45, 56, 67, 1, 100, 340, 90]
""" Normal Iteration """
start_time = time.time()
for item in itemlist:
if item % 2 == 0:
print(item)
end_time = time.time()
print("Without List Comprehension : " + str(end_time - start_time))
""" List Comprehension """
start_time = time.time()
[print(item) for item in itemlist if item % 2 == 0]
end_time = time.time()
print("With List Comprehension : " + str(end_time - start_time))
56
100
340
90
Without List Comprehension : 0.0002067089080810547
56
100
340
90
With List Comprehension : 0.00019121170043945312