Skip to content

Instantly share code, notes, and snippets.

@bootrino
Created August 22, 2022 00:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bootrino/68e73beec86fb65dbac87b2f3b56d857 to your computer and use it in GitHub Desktop.
Save bootrino/68e73beec86fb65dbac87b2f3b56d857 to your computer and use it in GitHub Desktop.
list_to_path
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