Delete date, time from text list in Python

Question:

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)
Asked By: sam sami

||

Answers:

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

Answered By: AliReza shirazi
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.