Is it possible to directly expand multiple lists using a tuple of lists returned by a function?

I have a function that checks the files and directories in this function and returns a tuple of lists, for example addedFiles, removedFiles, addedDirs, removedDirs. Each of the named subscriptions in the tuple will be a list of strings (or empty). I need to add the results returned by the function to local versions of these lists.

This highly modified one demonstrates the result that I get after:

addedFiles, removedFiles, addedDirs, removedDirs = [],[],[],[]

for dir in allDirs:
    a,b,c,d = scanDir( dir )
    addedFiles.extend( a )
    removedFiles.extend( b )
    addedDirs.extend( c )
    removedDirs.extend( d )

But, I want to know if there is a better way to execute a section inside a loop for?
It's as if it's just a little ... ugly.

+3
source share
2 answers

What about:

 for a,b in zip(lists, extendwith):
     a.extend(b)
+6
source
params = ('addedFiles', 'removedFiles', 'addedDirs', 'removedDirs')
paramDict = dict((param, []) for param in params)

for dir in allDirs:
    for param, data in zip(params, scanDir(dir)):
        paramDict[param].extend(data)

.

+2

All Articles