Skip to content

Instantly share code, notes, and snippets.

@Omig12
Last active March 17, 2017 19:45
Show Gist options
  • Save Omig12/e4ff3f9d0f940fbef082914e2add020b to your computer and use it in GitHub Desktop.
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.
#!/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