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