small rewrites
This commit is contained in:
parent
c98f9027e0
commit
16c8d13f3c
@ -5,13 +5,13 @@ file_name: str = "simple"
|
|||||||
|
|
||||||
def find_hamlet_lines(text: str) -> list[str]:
|
def find_hamlet_lines(text: str) -> list[str]:
|
||||||
# Define the regular expression pattern
|
# Define the regular expression pattern
|
||||||
pattern = re.compile(r".*Hamlet.*", re.IGNORECASE)
|
pattern = re.compile(r"Hamlet", re.IGNORECASE)
|
||||||
|
|
||||||
# Split the text into lines
|
# Split the text into lines
|
||||||
lines = text.split("\n")
|
lines = text.split("\n")
|
||||||
|
|
||||||
# Use the regular expression to find lines containing "Hamlet"
|
# Use the regular expression to find lines containing "Hamlet"
|
||||||
hamlet_lines = [line for line in lines if re.match(pattern, line)]
|
hamlet_lines = [line for line in lines if re.search(pattern, line)]
|
||||||
|
|
||||||
return hamlet_lines
|
return hamlet_lines
|
||||||
|
|
||||||
|
@ -11,9 +11,7 @@ def find_pies_lines(text: str) -> list[str]:
|
|||||||
lines = text.split("\n")
|
lines = text.split("\n")
|
||||||
|
|
||||||
# Use the regular expression to find lines containing "pies"
|
# Use the regular expression to find lines containing "pies"
|
||||||
pies_lines = [
|
pies_lines = [line for line in lines if re.search(pattern, line)]
|
||||||
line for _, line in enumerate(lines, start=1) if re.search(pattern, line)
|
|
||||||
]
|
|
||||||
|
|
||||||
return pies_lines
|
return pies_lines
|
||||||
|
|
||||||
|
@ -5,15 +5,13 @@ file_name: str = "simple"
|
|||||||
|
|
||||||
def find_dates_1900_to_1999(text):
|
def find_dates_1900_to_1999(text):
|
||||||
# Define the regular expression pattern
|
# Define the regular expression pattern
|
||||||
pattern = re.compile(r".*19\d{2} r\..*", re.IGNORECASE)
|
pattern = re.compile(r"19\d{2} r\.", re.IGNORECASE)
|
||||||
|
|
||||||
# Split the text into lines
|
# Split the text into lines
|
||||||
lines = text.split("\n")
|
lines = text.split("\n")
|
||||||
|
|
||||||
# Use the regular expression to find lines containing dates from 1900 to 1999
|
# Use the regular expression to find lines containing dates from 1900 to 1999
|
||||||
date_lines = [
|
date_lines = [line for line in lines if re.search(pattern, line)]
|
||||||
line for _, line in enumerate(lines, start=1) if re.match(pattern, line)
|
|
||||||
]
|
|
||||||
|
|
||||||
return date_lines
|
return date_lines
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user