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
Post a Comment