Imagine how we might do this problem by hand. To aid in this let's make a toy problem with only 2 files but there could be many more files. The two files are fruit.txt and veg.txt. fruit.txt a apple b banana d date c cherry veg.txt asparagus a beets b carrot c eggplant e run: joincol.py fruit.txt 1 veg.txt 2 we get: a apple asparagus b banana beets c cherry carrot d date - e - eggplant for the file fruit we want a dictionary called: dictOfDict["fruit.txt"] It is found in the dictionary dictOfDict. Here is how you could create it by hand: dictOfDict = {} dictOfDict["fruit.txt"] = {} # index each line in the in fruit.txt by the contents of the match column in fruit.txt in # dictOfDict["fruit.txt"]: dictOfDict["fruit.txt"]["a"] = "apple" dictOfDict["fruit.txt"]["b"] = "banana" dictOfDict["fruit.txt"]["d"] = "date" dictOfDict["fruit.txt"]["c"] = "cherry" # for the file veg.txt you want: dictOfDict["veg.txt"] = {} dictOfDict["veg.txt"]["a"] = "asparagus" dictOfDict["veg.txt"]["b"] = "beets" dictOfDict["veg.txt"]["c"] = "carrots" dictOfDict["veg.txt"]["e"] = "eggplant" Now you want to create a set of values in the matching columns. The set of all the values in the matching column for dictOfDict["veg.txt"] is the set of dictOfDict["veg.txt"].keys(). that is: set(dictOfDict["veg.txt"].keys()) Similarly for the other files. These are sets. What you want is the union of all of these sets. There is a union operator. finally, for each key in the union of all of the sets of keys you want to index each file's dictionary entry and look up in that dictionary using the key. This is two nested fors. # roughly like this but maybe a couple more lines to get the print right for key in setOfKeys : for file in dictOfDict.keys() : print some stuff To handle missing values like dictOfDict["fruit.txt"]["e"] and dictOfDict["veg.txt"]["d"] use the get(key, default) method on dictionary to return a default value if the key is not in the dictionary.