Skip to content

Instantly share code, notes, and snippets.

@sidharthshah
Last active November 8, 2015 04:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sidharthshah/c1398bad23c21f2dced2 to your computer and use it in GitHub Desktop.
Save sidharthshah/c1398bad23c21f2dced2 to your computer and use it in GitHub Desktop.
Simple way to format name
from string import strip
def format_name(name):
#Step 1: Split by ,
#Step 2: Remove any extrac white space in tokens using Map
#Step 3: Reverse List using ::-1
#Step 4: Join with White Space
return " ".join(map(strip, name.split(","))[::-1])
>>> format_name("Shah, Saheb")
'Saheb Shah'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment