Home > Article > Backend Development > Python filters out a sensitive word in a string array
Use the filter function to implement a conditional judgment function.
For example, if you want to filter out a certain sensitive word in a string array, the sample code is as follows:
#filter out some unwanted tags def passed(item): try: return item != "techbrood" #can be more a complicated condition here except ValueError: return False org_words = [["this","is"],["demo","from"],["techbrood"]] words = [filter(passed, item) for item in org_words]
Note that Python2.x and Python3.x are not compatible with filter/map processing. In Python2 .x directly returns a list.
In Python3.x, an iterable object is returned, such as 9511eb37ecd99d90ad6638231e83323d, and the following string of numbers is the object reference address.
You can use list(words) conversion.
The above is the detailed content of Python filters out a sensitive word in a string array. For more information, please follow other related articles on the PHP Chinese website!