Created
April 19, 2022 09:58
-
-
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.
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/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