Skip to content

Instantly share code, notes, and snippets.

@hornc
Created May 18, 2023 03:06
Show Gist options
  • Save hornc/c1d767b624e43175c91739f814b23f39 to your computer and use it in GitHub Desktop.
Save hornc/c1d767b624e43175c91739f814b23f39 to your computer and use it in GitHub Desktop.
Validate and format ISSNs
# Validate and format ISSNs
def validISSN(issn):
issn = issn.upper().replace('X', 'A').replace('-', '')
return len(issn) == 8 and sum((8 - i) * int(n, 16) for i, n in enumerate(issn)) % 11 == 0
def formatISSN(issn):
issn = issn.upper().replace('-', '')
return f'{issn[:4]}-{issn[4:]}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment