Skip to content

Instantly share code, notes, and snippets.

@wonderbeyond
Created July 21, 2025 06:44
Show Gist options
  • Save wonderbeyond/033a9adad331ddcff64d058e8b7c74c0 to your computer and use it in GitHub Desktop.
Save wonderbeyond/033a9adad331ddcff64d058e8b7c74c0 to your computer and use it in GitHub Desktop.
[python] Locate line match some pattern in file
"""
Help me implement the Python function,
def locate_line(filename, pattern: str, after: str|None, until: str|None) -> int: ...
It finds the first line in file matching the re pattern and returns the 1-based lineno, 0 means nothing found. The after and until params specify the optional searching range.
Please write concise, clear but readable code.
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment