Skip to content

Instantly share code, notes, and snippets.

@pschanely
Created June 26, 2025 18:33
Show Gist options
  • Save pschanely/aea70ac11fac42fcabda865357349beb to your computer and use it in GitHub Desktop.
Save pschanely/aea70ac11fac42fcabda865357349beb to your computer and use it in GitHub Desktop.
Shared via CrossHair Playground
import re
from typing import Optional
def parse_year(yearstring: str) -> Optional[int]:
'''
Something is wrong with this year parser! Can you guess what it is?
'''
year = int(yearstring) if re.match('[1-9][0-9][0-9][0-9]', yearstring) else None
assert year is None or 1000 <= year <= 9999
return year
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment