yuliji
4/21/2016 - 1:35 PM

a lot of string operation, separate first last name

a lot of string operation, separate first last name

#coding=utf-8

def split_first_last_name(fullname):
    if (" " in fullname):
        seperator = fullname.find(" ")
        firstname = fullname[0:seperator]
        lastname = fullname[seperator+1:len(fullname)]
        return [firstname, lastname]
    elif (fullname.isalpha()):
        return ["", fullname]
    else:
        #print type(fullname)
        #print len(fullname)
        fullname = fullname.decode('utf-8')
        #print type(fullname)
        #print fullname
        if( len(fullname) > 3):
            return [fullname[2:], fullname[0:2]]
        else:
            return [fullname[1:], fullname[0:1]]