daily pastebin goal
52%
SHARE
TWEET

Untitled

a guest Feb 20th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ["hello","18hs","18aaa","21hr"]
  2.      
  3. >>> import re
  4. >>> words = ["hello", "18hs", "18aaa", "21hr"]
  5. >>> [w for w in words if not re.match(r'd+h', w)]
  6. ['hello', '18aaa']
  7.      
  8. my_list = ["hello","18hs","18aaa","21hr"] # input data
  9.  
  10. custom_filters = [lambda x: not x.endswith('hr'),  
  11.                   lambda x: not x.endswith('hs'),
  12.                   lambda x: not x.endswith('h')] # define custom filters
  13.  
  14. final = list(filter(lambda x: all([custom_filter(x) for custom_filter in custom_filters]), my_list)) # apply custom filters one by one
  15.  
  16. # should result in ["hello", "18aaa"]
  17.      
  18. >>> import re
  19. >>> words = ["hello", "18hs", "18aaa", "21hr"]
  20. >>> [w for w in words if not re.match(r'd+h', w)]
  21. ['hello', '18aaa']
  22.      
  23. >>> words = ["hello", "18hs", "18aaa", "21hr", '7hg']
  24. >>> [w for w in words if not re.match(r'd+h(s|r)$', w)]
  25. ['hello', '18aaa', '7hg']
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top