Last active
June 25, 2021 10:15
-
-
Save mikekenneth/f90dcb317b52ded409baf0f3a96d0dd2 to your computer and use it in GitHub Desktop.
Code: 3 Letters code from Surname
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
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