What is the pythonic way of writing the following code?
extensions = ['.mp3','.avi']
file_name = 'test.mp3'
for extension in extensions:
if file_name.endswith(extension):
#do stuff
I have a vague memory that the explicit declaration of the for
loop can be avoided and be written in the if
condition. Is this true?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…