View Full Version : list comprehension are great!!!

11 November 2012, 07:04 AM
I was about to post a problem here and while i was posting i discovered a solution looking at the code,

for each in os.listdir(locationTxt):
if os.path.isdir(os.path.join(locationTxt,each)):
if each not in hideTheseFolders:#hide directory in scrolllist

the code above is self explanatory of what i want to achieve,

so through list comprehension in just two lines,
for each in [each for each in os.listdir(locationTxt) if os.path.isdir(os.path.join(locationTxt,each)) and each not in hideTheseFolders]:
cmds.textScrollList('fileLister', edit=True,append=each)

so now I understood list comprehension i hope this logic helps someone else too...

11 November 2012, 07:21 AM
It does use less lines of code, but I prefer not using too much of it, a bit confusing

11 November 2012, 07:52 AM
Is your objective code obfuscation? Because faster it won't be.

CGTalk Moderation
11 November 2012, 07:52 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.