Matching strings for multiple data set in Python
Question: I am working on python and I need to match the strings of several data files.
First I used pickle to unpack my files and then I place them into a list. I
only want to match strings that have the same conditions. This conditions are
indicated at the end of the string.

My working script looks approximately like this:

    
    
    import pickle
    
    f = open("data_a.dat")
    list_a = pickle.load( f )
    f.close()
    
    f = open("data_b.dat")
    list_b = pickle.load( f )
    f.close()
    
    f = open("data_c.dat")
    list_c = pickle.load( f )
    f.close()
    
    f = open("data_d.dat")
    list_d = pickle.load( f )
    f.close()
    
    
    for a in list_a:
        for b in list_b:
            for c in list_c
                for d in list_d:
                     if a.GetName()[12:] in b.GetName(): 
                          if a.GetName[12:] in c.GetName():
                             if a.GetName[12:] in d.GetName():
                                  "do whatever"
    

This seems to work fine for these 2 lists. The problems begin when I try to
add more 8 or 9 more data files for which I also need to match the same
conditions. The script simple won't process and it gets stuck. I appreciate
your help.

Edit: Each of the lists contains histograms named after the parameters that
were used to create them. The name of the histograms contains these parameters
and their values at the end of the string. In the example I did it for 2 data
sets, now I would like to do it for 9 data sets without using multiple loops.

Edit 2. I just expanded the code to reflect more accurately what I want to do.
Now if I try to do that for 9 lists, it does not only look horrible, but it
also doesn't work.


Answer: out of my head:

    
    
    files = ["file_a", "file_b", "file_c"]
    sets = []
    
    for f in files:
        f = open("data_a.dat")
        sets.append(set(pickle.load(f)))
        f.close()
    
    intersection = sets[0].intersection(*sets[1:])
    

EDIT: Well I overlooked your mapping to x.GetName()[12:], but you should be
able to reduce your problem to set logic.

