def add_dir_to_list(dirlist, dir):
 if ((dir is not None) and os.path.isdir(dir) and (dir not in dirlist)):
  dirlist.insert(0, dir)

def add_dir_to_list ( dirlist , dir ) : if ( ( dir is not None ) and os . path . isdir ( dir ) and ( dir not in dirlist ) ) : dirlist . insert ( 0 , dir )
add the directory dir to the list dirlist if 1) dir is not already in dirlist 2) dir actually exists .