python - List Comprehensions and Conditions? -
I am trying to see if I can improve this code by using list encoding.
tell me that I have the following list:
a_list = ['hello', 'foo', 'fo1bar', 'rubber', 'showbar']] regex_list = [ Lambda x: re-search (R'fu ', X, re.IGNORECASE), lambda x: re-search (R'RO, X, RE, NICACASE)] I Want to add all the elements that do not have anyone in any other list in regex_list match
e.g. Regex_list for regex: if (regex (each) == none): newlist.append (each)
How can I use this list understanding? Is this also possible?
Sure, I think it should
newlist = [For a s in the regex_list for r (not r) for r)] edit : On closer inspection, I notice that your example code is actually Adds to the new list in a_list each string that does not match all regexes - and what it does, it adds each string to each rezx once it matches Not my list Understand, which I think means to you, which adds only one copy of each string that does not match the regexes of any .
Comments
Post a Comment