list comprehension - In python exclude folders which start with underscore or more than six characters long -


i want store folder names except folders start underscore (_) or have more 6 characters.to list, use code

folders = [name name in os.listdir(".") if os.path.isdir(name)] 

what change need make desired output.

well simplest way extend if clause of list comprehension contain 2 more clauses:

folders = [name name in os.listdir(".")             if os.path.isdir(name) , name[0] != '_' , len(name) <= 6] 

Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -