Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Python initial generator using regular expressions
#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