Practice problem

python

#1

Hello friends, I try to solve some problems for my practice.Today I was trying to code a small function to list all my audio files into one folder.I have coded following solution.Can anybody offer their views on my code?

import os
def ScanAudioFiles(FoldPath):
  my_audioFiles=[]
  audioFiles_Ext=["mp3","mp4","wmv","3gp"]
  allFiles=os.listdir(FoldPath)
  for audioExt in audioFiles_Ext:
    for fileName in allFiles:
      if audioFiles_Ext in fileName:
        my_audioFiles.append(fileName)
        
  return my_audioFiles

#2
import os
def ScanAudioFiles(FoldPath):
    audioFiles_Ext=["mp3","mp4","wmv","3gp"]
    allFiles=os.listdir(FoldPath)
    return [fileName for fileName in allFiles if fileName[-3:] in audioFiles_Ext]

#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.