Skip to content

Instantly share code, notes, and snippets.

@adrianbiro
Created April 19, 2022 09:58
Show Gist options
  • Save adrianbiro/e8ef2ace657965e653f657b23d0f8893 to your computer and use it in GitHub Desktop.
Save adrianbiro/e8ef2ace657965e653f657b23d0f8893 to your computer and use it in GitHub Desktop.
While splitting a string by slashes in order to extract the last part as a name, a problem occurs in the case that string eg. URL ends with a slash. Here is a solution.
#!/usr/bin/python3
*_, name = url.split('/')
if not name:
*_, name, _ = url.split('/')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment