Classifying files in a directory by file extension I have the following code:

resolved = []
rejected = []
for file in files_within("./_input/"):
    file = File(file)
    if file.extension.lower() == "gdb":
        resolved.append(file)
    else:
        rejected.append(file)
MAP["resolved"] = resolved
MAP["rejected"] = rejected


And i would like to improve it to avoid this part:

MAP["resolved"] = resolved
MAP["rejected"] = rejected


But without affecting the performance.

I was thinking about that:

MAP["resolved"] = []
MAP["rejected"] = []
for file in files_within("./_input/"):
    file = File(file)
    if file.extension.lower() == "gdb":
        MAP["resolved"].append(file)
    else:
        MAP["rejected"].append(file)


But i don't know if is a good practice.

Python version 2.6.
Each MAP["resolved"] has to perform a hash on "resolved", and then check up the value in the dictionary's internal structure.
This is more costly then looking up a single variable.

Just like in the first, you can assign a local variable, resolved, but you can assign to the dictionary at the same time:

resolved = MAP["resolved"] = []


If you only mutate resolved, then you mutate MAP["resolved"] too. So you can't overwrite resolved with resolved = ['new list'], for example.
Which can get you:

MAP["resolved"] = resolved = []
MAP["rejected"] = rejected = []
for file in files_within("./_input/"):
    file = File(file)
    if file.extension.lower() == "gdb":
        resolved.append(file)
    else:
        rejected.append(file)


I am also unsure on what your functions are, I don't remember them being in the standard library, and so I won't suggest any changes to them.