Created
August 22, 2022 00:08
-
-
Save bootrino/68e73beec86fb65dbac87b2f3b56d857 to your computer and use it in GitHub Desktop.
list_to_path
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
def list_to_path(path_element_list, topslash=False, tailslash=False): | |
# strips leading and trailing slashes from each element and returns without leading and trailing slashes i.e. 'a/b/c' | |
# drop empty list elements | |
path_element_list = [x for x in path_element_list if x] | |
path = '/'.join([x.strip('/') for x in path_element_list]) | |
if topslash: | |
path = '/' + path | |
if tailslash: | |
path = path + '/' | |
return path | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment