Skip to content

Instantly share code, notes, and snippets.

@pschanely
Created July 17, 2024 09:52
Show Gist options
  • Save pschanely/2c907fb6bad4a7f53fbfe133ff985ae2 to your computer and use it in GitHub Desktop.
Save pschanely/2c907fb6bad4a7f53fbfe133ff985ae2 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?
post: __return__ is None or 1000 <= __return__ <= 9999
'''
return int(yearstring) if re.match('[1-9][0-9][0-9][0-9]', yearstring) else None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment