compare two Lists and set a value if the matched items empty or not

Viewed 15

i'am working on the orders picking from store locations and i am looking for the matched items for each order and each aisle. If the matched items is not empty, so the picker need to travel through the aisle and the distance is set to the Length of the aisle. Otherwise the distance is zero but i can't get the value zero for this case. it gives me only an empty array.

list_article=['m', 'y', 'n', 'b', 'i', 'q', 'p', 'a', 'c', 'd','e','f', 'g', 'h', 'j']
dvar={}                      # distance 
match_items={}
Aisle_arct={1:['m','b','p','d','g'], 2:['y','i','a','e','h'], 3:['n','q','c','f','j']} # items in Aisle 
for iorder in N:
    limit=rnd.randint(1,15)
    Order ={iorder:random.sample(list_article,limit)}    # generate Lists of orders
    print(Order)
    for kaisle in Aisle_arct :
        match_items[iorder,kaisle]=[]
        dvar[iorder,kaisle]=[]
        for z in Order[iorder] :
            if z in Aisle_arct[kaisle] :
                match_items[iorder,kaisle].append(z)
                if match_items[iorder,kaisle]:
                    dvar[iorder,kaisle]=50          
                else:
                    dvar[iorder,kaisle]=0

print(match_items)
print(dvar)

Output:

{1: ['h', 'p', 'g', 'j', 'm', 'i', 'c', 'a', 'b', 'n', 'f', 'q', 'd']}
{2: ['f', 'y', 'e', 'q', 'a', 'c']}
{3: ['c']}
{4: ['a', 'h', 'c', 'i']}

{(1, 1): ['p', 'g', 'm', 'b', 'd'], (1, 2): ['h', 'i', 'a'], (1, 3): ['j', 'c', 'n', 'f', 'q'], (2, 1): [], (2, 2): ['y', 'e', 'a'], (2, 3): ['f', 'q', 'c'], (3, 1): [], (3, 2): [], (3, 3): ['c'], (4, 1): [], (4, 2): ['a', 'h', 'i'], (4, 3): ['c']}

{(1, 1): 50, (1, 2): 50, (1, 3): 50, (2, 1): [], (2, 2): 50, (2, 3): 50, (3, 1): [], (3, 2): [], (3, 3): 50, (4, 1): [], (4, 2): 50, (4, 3): 50}

I need to have all the values of dvar, but the zero doesn't appear. Can someone help me to figure it out? Thks James

0 Answers
Related