Last active
March 17, 2017 19:45
-
-
Save Omig12/e4ff3f9d0f940fbef082914e2add020b to your computer and use it in GitHub Desktop.
This function allows an user to reverse a sub-string within a string or a sub-list within a list. I don't know why but this might be useful to someone.
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
#!/usr/bin/env python3 | |
# l = Full list or string to be reversed. | |
# start = Index where the sub-string to be reversed starts | |
# end = Index where the sub-string to be reversed ends | |
def rev_sub(l, start, end): | |
return l[0:start]+l[start:end+1][::-1]+l[end+1:] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment