'while loop with dynamic list in python using many dicionnaries

To follow up on the request I made previously in the following link: while loop with dynamic list in python using a dictionnary,

I have many dictionnaries (dict1, dict2, dict3, ....) like bellow:

dict1 = {
    1: [0, 1, 'some_site', 3, 'some_site_2'],
    2: [0, 1, 'some_site_2', 3, 'some_site_3'],
    3: [0, 1, 'some_site_2', 3, 'some_site_4'],
    4: [0, 1, 'some_site_3', 3, 'some_site_5'],
}
dict2 = {
    1: [0, 1, 'siteA1', 3, 'siteA12'],
    2: [0, 1, 'some_site_2', 3, 'some_site_3'],
    3: [0, 1, 'some_site5', 3, 'some_site_6'],
    4: [0, 1, 'some_site_3', 3, 'some_site_5'],
}

dict3 = {
    1: [0, 1, 'siteA1', 3, 'siteA'],
    2: [0, 1, 'some_site_2', 3, 'some_site_3']
}
.
.
.

I would like to check from a data site_SI = 'some_site' in val[2] of one or from many dictionnaries and take its data from val[4] and then look for this data in Val[2] of another line (key) and take its data in val[4] and continue until it finds the last value of val[4] in val[2], this one is done, but now, I want to check if one of its intermediate values or/ and the last value can be found in the other dictionaries and add each line from dictX to list_def_from_dictX

This is my code for checking in one dictionnary:

list_def_from_dict1 = list()
list_def_from_dict2 = list()
list_def_from_dict3 = list()
.
.   # lists for each val founds in each dictionnary 
.

site_SI = 'some_site'
unvisited = Queue()
unvisited.put(site_SI)
while not unvisited.empty():
    ele = unvisited.get()
    for key, val in dict1.items():
        if val[2] == ele:
            unvisited.put(val[4])
            list_def.append(val)
            print(val)

So what's the modification I need to do here in my first code to do the same thing and to check in the other dictionnaries if there are one of the values added before in unvisited



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source