Having following:
list1 = ['something',"somet'hing",'somet"hing','some;thing','']
list2 = [';','"',"'"]
I would like to get filtered list1 if string inside list contain any of the character from list2 or string is blank. Desired output:
list3 = ['something']
Currently I'm doing it manually like this:
list1withoutEmptyLines= list(filter(None, list1))
list1withoutQuote = [x for x in list1withoutEmptyLines if "'" not in x]
list1withoutDoublequotes = [x for x in list1withoutQuote if "\"" not in x]
list1withoutSemicolon = [x for x in list1withoutDoublequotes if ";" not in x]
and It works perfectly fine. I also tried to automate it through creating list of forbidden characters like this:
forbiddenCharacters = ['"', ';', '\'']
filteredLines = []
for character in forbiddenCharacters:
filteredLines = [x for x in uniqueLinesInFile if character not in x]
but list called filteredLines still contains strings with semicolon ";". Any advice will be appreciated.
[x for x in list1 if not any(y in x for y in list2)]filteredLinesin each iteration.