← Back to challenges

Get the File Name

PythonMediumregexlanguage_fundamentalsarrays

Instructions

Create a function that returns the selected filename from a path. Include the extension in your answer.

Examples

get_filename("C:/Projects/pil_tests/ascii/innokodakademija.txt") ➞ "innokodakademija.txt"

get_filename("C:/Users/johnsmith/Music/Beethoven_5.mp3") ➞ "Beethoven_5.mp3"

get_filename("ffprobe.exe") ➞ "ffprobe.exe"

Notes

  • Tests will include both absolute and relative paths.
  • For simplicity, all paths will include forward slashes.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Minimal IV: if-elif-else Inferno