1# Python3 program to Filter list of
2# strings based on another list
3import re
4
5def Filter(string, substr):
6 return [str for str in string
7 if re.match(r'[^\d]+|^', str).group(0) in substr]
8
9# Driver code
10string = ['city1', 'class5', 'room2', 'city2']
11substr = ['class', 'city']
12print(Filter(string, substr))
13