Created
February 18, 2019 08:41
-
-
Save reganto/551004e825dfea9ff37231ed063d3db0 to your computer and use it in GitHub Desktop.
Substitute indices in Python strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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