Filename Extension Checker

Easy ⏱ 8 min 85% acceptance ★★★★☆ 4.3
Write has_valid_extension(filename, extensions) that returns True if filename ends with one of the extensions in the list extensions (each like .jpg), matching case-insensitively.

Examples

Example 1
Input
filename = 'photo.JPG', extensions = ['.jpg', '.png']
Output
True
Explanation

'.JPG' matches '.jpg' case-insensitively.

Example 2
Input
filename = 'notes.txt', extensions = ['.jpg', '.png']
Output
False
Explanation

No extension in the list matches.

Constraints

  • extensions is a non-empty list of strings starting with a dot.

Topics

Stringsstartswith/endswith

Companies

NetflixAdobeCisco

Hints

Hint 1

Lowercase both the filename and the extension list before comparing.

Hint 2

`str.endswith()` accepts a tuple of suffixes.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.