Last active
January 19, 2021 22:57
-
-
Save sojohnnysaid/6ea1adeff0cf8299768fda722f86ac21 to your computer and use it in GitHub Desktop.
Python initial generator using regular expressions
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
#Extract users initials | |
from cs50 import get_string | |
import re | |
def main(): | |
userName = get_string("enter full name: ") | |
print(getInitials(userName)) | |
def getInitials(fullName): | |
list = re.findall(r'(^[a-zA-Z]|(?<=\s)[a-zA-Z])', fullName) | |
return '.'.join([i.upper() for i in list]) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment