Skip to content

Instantly share code, notes, and snippets.

@mikekenneth
Last active June 25, 2021 10:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikekenneth/f90dcb317b52ded409baf0f3a96d0dd2 to your computer and use it in GitHub Desktop.
Save mikekenneth/f90dcb317b52ded409baf0f3a96d0dd2 to your computer and use it in GitHub Desktop.
Code: 3 Letters code from Surname
def get_surname_code(surname: str, fill_string='0') -> str:
seperators, i, pos = ("'", " ", "-"), 0, 0
for letter in surname:
i += 1
if letter in seperators:
pos = i
return surname[pos:pos+3].upper().ljust(3,fill_string)
# Example:
print(get_surname_code('DA SILVA'))
print(get_surname_code("D'ALMEIDA"))
print(get_surname_code('DE SOUZA'))
print(get_surname_code('SEHO'))
print(get_surname_code('DA'))
print(get_surname_code('SE'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment