Created
May 18, 2023 03:06
-
-
Save hornc/c1d767b624e43175c91739f814b23f39 to your computer and use it in GitHub Desktop.
Validate and format ISSNs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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