For example, I have the following list
*,', '2:24', 'PM', 'Python', 'Jul', '1,', '2022,', '2:23', 'PM', 'Python', 'Jul', '1,', '2022,', '2:23', 'PM', 'Python'*
I want to delete the rest of my list except for my words that are in the Python example
my_file = open("1.txt", "r")
content = my_file.read()
content_list = content.split()
my_file.close()
OutputList = filter(
lambda ThisWord: not re.match('^(?:(?:[0-9]{2} [:\/,]){2}[0-9:0-9]{2}|AM|PM|Jul|Jun)$', ThisWord),
content_list)
for ThisValue in OutputList:
print (ThisValue)
CodePudding user response:
lambda ThisWord: not re.match('\d{4}|Jul|Jun|PM|AM|[0-9][:][0-9]|[0-9]{1}', ThisWord),
content_list)
Add the other months of the year to the code