Skip to content

Instantly share code, notes, and snippets.

@srafay
Created April 1, 2019 05:50
Show Gist options
  • Save srafay/cf4fe0e2da5547d7fdaa517e4a4a6dce to your computer and use it in GitHub Desktop.
Save srafay/cf4fe0e2da5547d7fdaa517e4a4a6dce to your computer and use it in GitHub Desktop.
Function for masking middle elements in a string
def mask_middle(text):
text = str(text)
if len(text) > 2:
return text[0] + "*" * (len(text) - 2) + text[len(text) - 1]
return "*" * len(text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment