def CleanList(list, folder, files):
 for path in sorted(list.keys()):
  (fld, name) = os.path.split(path)
  if (fld == folder):
   present = False
   for name in files:
    if (os.path.join(folder, name) == path):
     present = True
     break
   if (not present):
    del list[path]

def CleanList ( list , folder , files ) : for path in sorted ( list . keys ( ) ) : ( fld , name ) = os . path . split ( path ) if ( fld == folder ) : present = False for name in files : if ( os . path . join ( folder , name ) == path ) : present = True break if ( not present ) : del list [ path ]
remove elements of "list" not found in "files" .