0

I am trying to run the following program as part of my other program

n=2

array=[[[[[[['*' for col in range(6)] for col in range(n)] for col in range(n)] for col in range(n)] for row in range(n)] for row in range(n)]for row in range(n)]

possible=[[[[[[[] for col in range(n)] for col in range(n)] for col in range(n)] for row in range(n)] for row in range(n)] for row in range(n)]

possible[0][0][0][0][0][0]=[['a', 'f', 'b', 'c', 'd', 'e'], ['a', 'f', 'b', 'c', 'e', 'd'], ['a', 'f', 'b', 'd', 'c', 'e'], ['a', 'f', 'b', 'e', 'c', 'd'], ['a', 'f', 'c', 'b', 'd', 'e'], ['a', 'f', 'c', 'b', 'e', 'd'], ['a', 'f', 'd', 'b', 'c', 'e'], ['a', 'f', 'e', 'b', 'c', 'd'], ['a', 'f', 'c', 'd', 'b', 'e'], ['a', 'f', 'c', 'e', 'b', 'd'], ['a', 'f', 'd', 'c', 'b', 'e'], ['a', 'f', 'e', 'c', 'b', 'd'], ['a', 'e', 'b', 'f', 'c', 'd'], ['a', 'e', 'b', 'c', 'f', 'd'], ['a', 'e', 'c', 'f', 'b', 'd'], ['a', 'e', 'c', 'b', 'f', 'd'], ['f', 'a', 'b', 'c', 'd', 'e'], ['f', 'a', 'b', 'c', 'd', 'e'], ['f', 'a', 'b', 'c', 'd', 'e'], ['f', 'a', 'b', 'c', 'd', 'e'], ['f', 'a', 'b', 'c', 'd', 'e'], ['f', 'a', 'b', 'c', 'd', 'e'], ['f', 'a', 'b', 'c', 'd', 'e'], ['f', 'a', 'b', 'c', 'd', 'e'], ['f', 'a', 'b', 'c', 'd', 'e'], ['f', 'a', 'b', 'c', 'd', 'e'], ['f', 'a', 'b', 'c', 'd', 'e'], ['f', 'a', 'b', 'c', 'd', 'e']]

array[1][0][0][0][0][0]=['a', 'b', 'f', 'd', 'e', 'c']

array[0][0][0][0][0][0]=['*', '*', 'f', 'c', 'd', '*']

r=[]
for s in range(6):
    if s!=0:
        if array[0][0][0][0][0][0][s]!='*':
            r.append(s)
            
x=[]
for y in range(6):
    if y!=0:
        if array[1][0][0][0][0][0][y]!='*':
            x.append(y)

t=list(set(x).intersection(set(r)))

for j in t:
    if (array[1][0][0][0][0][0][j]!=array[0][0][0][0][0][0][j]):
        for i in possible[0][0][0][0][0][0]:
            if i[0]==array[1][0][0][0][0][0][0]:
                possible[0][0][0][0][0][0].remove(i)

Output is

[['a', 'f', 'b', 'e', 'c', 'd'], ['a', 'f', 'e', 'b', 'c', 'd'], ['a', 'f', 'e', 'c', 'b', 'd'], 
 ['a', 'e', 'c', 'b', 'f', 'd'], ['f', 'a', 'b', 'c', 'd', 'e'], ['f', 'a', 'b', 'c', 'd', 'e'], 
 ['f', 'a', 'b', 'c', 'd', 'e'], ['f', 'a', 'b', 'c', 'd', 'e'], ['f', 'a', 'b', 'c', 'd', 'e'], 
 ['f', 'a', 'b', 'c', 'd', 'e'], ['f', 'a', 'b', 'c', 'd', 'e'], ['f', 'a', 'b', 'c', 'd', 'e'], 
 ['f', 'a', 'b', 'c', 'd', 'e'], ['f', 'a', 'b', 'c', 'd', 'e'], ['f', 'a', 'b', 'c', 'd', 'e'], 
 ['f', 'a', 'b', 'c', 'd', 'e']]

print(possible[0][0][0][0][0][0]) should not have any list starting with 'a'. I don't understand what I am doing wrong.

azro
  • 53,056
  • 7
  • 34
  • 70
deep08
  • 1
  • 4
    But ***why*** are you trying to create 6 levels deep nested lists? – mkrieger1 May 07 '21 at 09:17
  • You have `possible[0][0][0][0][0][0]=[['a', 'f', 'b', 'c', 'd', 'e'], ...`, why did you think that `print(possible[0][0][0][0][0][0])` does not start with `'a'`? – mkrieger1 May 07 '21 at 09:18
  • I have to find some results on an allocation problem with six objects and 6 agents, where each agent can have 12 different type of linear orders on the objects. – deep08 May 07 '21 at 09:23
  • I am trying to remove all the entries inside possible[0][0][0][0][0][0] which have 'a' as the first element. – deep08 May 07 '21 at 09:25
  • 1
    It seems like you try to remove elements from `possible` while iterating over it, which may lead to unexpected results. Check out [this question](https://stackoverflow.com/questions/1207406/how-to-remove-items-from-a-list-while-iterating) for more info. – akocz May 07 '21 at 09:37

0 Answers0