Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

method get first last name python

def get_first_last_name(s):
    INVALID_NAME_PARTS = ["mr", "ms", "mrs",
    "dr", "jr", "sir"]
    parts = s.lower().replace(".","").strip().split()
    parts = [p for p in parts if p not in INVALID_NAME_PARTS]
    if len(parts) == 0:
        raise ValueError("Name %s is formatted wrong" %s)
    first,last = parts[0], parts[-1]
    first = first[0].upper() + first[1:]
    last = last[0].upper() + last[1:]
    
    return first, last
Comment

PREVIOUS NEXT
Code Example
Python :: flask socketio usage 
Python :: fizz buzz in python 
Python :: python check if key exist in json 
Python :: largest number python 
Python :: python print fraction 
Python :: python single line function 
Python :: django model query join 
Python :: check if any letter in string python 
Python :: Kivy Python ListView Scrollview with Toggle on off 
Python :: create requirements file and load it in new envirnment. 
Python :: Normalize columns in pandas dataframe2 
Python :: how to create a button using tkinter 
Python :: python recognize every white color 
Python :: requirement.txt for python 
Python :: python program to check whether a number is even or odd 
Python :: python evaluate string 
Python :: python return to top of loop 
Python :: python dictionary get value if key exists 
Python :: class inside class python 
Python :: pass args and kwargs to funcitons 
Python :: codechef solution 
Python :: reading from a file in python 
Python :: how to use list in python 
Python :: add image to pdf with python 
Python :: Add two numbers as a linked list 
Python :: most common letter in string python 
Python :: python use variable inside pandas query 
Python :: stack adt in python 
Python :: python iterate over string 
Python :: pandas check if column is object type 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =