Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ["hello","18hs","18aaa","21hr"]
- >>> import re
- >>> words = ["hello", "18hs", "18aaa", "21hr"]
- >>> [w for w in words if not re.match(r'd+h', w)]
- ['hello', '18aaa']
- my_list = ["hello","18hs","18aaa","21hr"] # input data
- custom_filters = [lambda x: not x.endswith('hr'),
- lambda x: not x.endswith('hs'),
- lambda x: not x.endswith('h')] # define custom filters
- final = list(filter(lambda x: all([custom_filter(x) for custom_filter in custom_filters]), my_list)) # apply custom filters one by one
- # should result in ["hello", "18aaa"]
- >>> import re
- >>> words = ["hello", "18hs", "18aaa", "21hr"]
- >>> [w for w in words if not re.match(r'd+h', w)]
- ['hello', '18aaa']
- >>> words = ["hello", "18hs", "18aaa", "21hr", '7hg']
- >>> [w for w in words if not re.match(r'd+h(s|r)$', w)]
- ['hello', '18aaa', '7hg']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement