Skip to content

Instantly share code, notes, and snippets.

@reganto
Created February 18, 2019 08:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reganto/551004e825dfea9ff37231ed063d3db0 to your computer and use it in GitHub Desktop.
Save reganto/551004e825dfea9ff37231ed063d3db0 to your computer and use it in GitHub Desktop.
Substitute indices in Python strings
# substitute indices in Python strings
def substitute(entry, i, j):
entry = list(entry)
entry[i], entry[j] = entry[j], entry[i]
return ''.join(entry)
# call sample
substitute('reganto', 1, 6)
# output 'rogante'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment