Yes, there is a more concise and Pythonic way to write the code you provided. You can use a combination of a list comprehension and the any() function to achieve the desired functionality. Here's an example of how you can rewrite the code:
extensions = ['.mp3', '.avi']
file_name = 'test.mp3'
if any(file_name.endswith(extension) for extension in extensions):
# Perform the necessary actions
In this code, the any() function is used along with a generator expression to iterate over each extension in the extensions list. The generator expression checks if the file_name ends with the current extension. If any of the conditions evaluate to True, indicating a match, any() returns True, and the code inside the if statement is executed.
By using this approach, you eliminate the need for an explicit for loop and condense the logic into a single line, making the code more concise and adhering to Python's guiding principles of readability and simplicity.