Filter python list

1

I need to remove elements from a list whose elements reference for removal are in another list:

# Esta lista foi gerada por combinação
lista original=[
    (182361, 243148, 360624, 364188), 
    (182361, 243148, 360624, 547083), 
    (182361, 243148, 360624, 486296), 
    (182361, 243148, 360624, 368820), 
    (182361, 243148, 360624, 365256), 
    (182361, 243148, 364188, 547083), 
    (182361, 243148, 364188, 486296), 
    (182361, 243148, 364188, 368820), 
    (182361, 243148, 364188, 365256), 
    (182361, 243148, 547083, 486296), 
    (182361, 243148, 547083, 368820), 
    (182361, 243148, 547083, 365256), 
    (182361, 243148, 486296, 368820), 
    (182361, 243148, 486296, 365256), 
    (182361, 243148, 368820, 365256), 
    (182361, 360624, 364188, 547083), 
    (182361, 360624, 364188, 486296), 
    (182361, 360624, 364188, 368820), 
    (182361, 360624, 364188, 365256), 
    (182361, 360624, 547083, 486296), 
    (182361, 360624, 547083, 368820), 
    (182361, 360624, 547083, 365256), 
    (182361, 360624, 486296, 368820), 
    (182361, 360624, 486296, 365256), 
    (182361, 360624, 368820, 365256), 
    (182361, 364188, 547083, 486296), 
    (182361, 364188, 547083, 368820), 
    (182361, 364188, 547083, 365256), 
    (182361, 364188, 486296, 368820), 
    (182361, 364188, 486296, 365256), 
    (182361, 364188, 368820, 365256), 
    (182361, 547083, 486296, 368820), 
    (182361, 547083, 486296, 365256), 
    (182361, 547083, 368820, 365256), 
    (182361, 486296, 368820, 365256), 
    (243148, 360624, 364188, 547083), 
    (243148, 360624, 364188, 486296), 
    (243148, 360624, 364188, 368820), 
    (243148, 360624, 364188, 365256), 
    (243148, 360624, 547083, 486296), 
    (243148, 360624, 547083, 368820), 
    (243148, 360624, 547083, 365256), 
    (243148, 360624, 486296, 368820), 
    (243148, 360624, 486296, 365256), 
    (243148, 360624, 368820, 365256), 
    (243148, 364188, 547083, 486296), 
    (243148, 364188, 547083, 368820), 
    (243148, 364188, 547083, 365256), 
    (243148, 364188, 486296, 368820), 
    (243148, 364188, 486296, 365256), 
    (243148, 364188, 368820, 365256), 
    (243148, 547083, 486296, 368820), 
    (243148, 547083, 486296, 365256), 
    (243148, 547083, 368820, 365256), 
    (243148, 486296, 368820, 365256), 
    (360624, 364188, 547083, 486296), 
    (360624, 364188, 547083, 368820), 
    (360624, 364188, 547083, 365256), 
    (360624, 364188, 486296, 368820), 
    (360624, 364188, 486296, 365256), 
    (360624, 364188, 368820, 365256), 
    (360624, 547083, 486296, 368820), 
    (360624, 547083, 486296, 365256), 
    (360624, 547083, 368820, 365256), 
    (360624, 486296, 368820, 365256), 
    (364188, 547083, 486296, 368820), 
    (364188, 547083, 486296, 365256), 
    (364188, 547083, 368820, 365256), 
    (364188, 486296, 368820, 365256), 
    (547083, 486296, 368820, 365256)
]

# pares de elementos que preciso remover da lista original, ou seja, 
# se na lista original contiver qualquer desses pares que eles sejam 
# substituidos por zero.
lista de remoção=[
    [182361, 547083], 
    [243148, 486296], 
    [360624, 368820], 
    [364188, 365256]
]

I need the output to be a list consisting of elements in groups of 4 (as in the original list) whose elements do not contain elements of the peer reference list. Where the presence of any pair of the removal list exists, this element is replaced by zero.

I would like it to look like this:

lista final =[  (182361, 243148, 360624, 364188), (0, 243148, 360624, 0),   (182361, 0, 360624, 0),  (182361, 243148, 0, 0), (182361, 243148, 360624, 365256),  (0, 243148, 364188, 0),  (182361, 0, 364188, 0), 
    (182361, 243148, 364188, 368820), (182361, 243148, 0,0), 
    (0, 0, 0, 0),  (0, 243148, 0, 368820), (0, 243148, 0, 365256), 
    (182361, 0,0, 368820),  (182361, 0,0, 365256), (182361, 243148, 368820, 365256),  (0, 360624, 364188, 0), (182361, 360624, 364188, 486296), 
    (182361, 0, 364188, 0),  (182361, 360624, 0,0), (0, 360624, 0, 486296), 
    (0, 0, 0, 0),  (0, 360624, 0, 365256), (182361, 0, 486296, 0), 
    (182361, 360624, 486296, 365256), (182361, 0, 0, 365256), 
    (0, 364188, 0, 486296),  (0, 364188, 0, 368820),  (0, 0, 0, 0), 
    (182361, 364188, 486296, 368820),  (182361, 0, 486296, 0), 
    (182361, 0, 368820, 0),  (0,0, 486296, 368820), (0,0, 486296, 365256), 
    (0,0, 368820, 365256),  (182361, 486296, 368820, 365256), (243148, 360624, 364188, 547083),  (0, 360624, 364188, 0), (243148, 0, 364188, 0), 
    (243148, 360624, 0,0),  (0, 360624, 547083, 0), (243148, 0, 547083, 0), 
    (243148, 360624, 547083, 365256),  (0, 0, 0, 0), (0, 360624, 0, 365256), 
    (243148, 0, 0, 365256),  (0, 364188, 547083, 0), (243148, 364188, 547083, 368820),  (243148, 0, 547083, 0), (0, 364188, 0, 368820), (0, 0, 0, 0), 
    (243148, 0, 368820, 0),  (0, 547083, 0, 368820),  (0, 547083, 0, 365256), 
    (243148, 547083, 368820, 365256),  (0,0, 368820, 365256), (360624, 364188, 547083, 486296), (0, 364188, 547083, 0),(360624, 0, 547083, 0), 
    (0, 364188, 486296, 0), (360624, 0, 486296, 365256), (0, 364188, 0, 365256), 
    (0, 547083, 486296, 0), (360624, 547083, 486296, 365256), (0, 547083, 0, 365256),  (0, 486296, 0, 365256), (364188, 547083, 486296, 368820), 
    (0, 547083, 486296, 0), (0, 547083, 368820, 0), (0, 486296, 368820, 0), 
    (547083, 486296, 368820, 365256)] 

This would be the final list after deleting the element pairs from the exclusion list.

    
asked by anonymous 12.11.2018 / 17:05

1 answer

0
lista_editada = []   # cria uma nova lista vazia
nao_foram_editados = [] # outra para os que nao foram editados
for grupo in lista_original:  # para cada grupo da lista
    foi_editado = False
    for teste in lista_remocao:  # testa todos da lista_remocao
        if all(item in grupo for item in teste): 
            # Achou o par! Removendo:
            grupo = tuple(0 if i in teste else i for i in grupo) 
            foi_editado = True

    lista_editada.append(grupo) # aqui adiciona todos os grupos
    if not foi_editado: # aqui adiciona os que nao sofreram edicao
         nao_foram_editados.append(grupo) 

print(lista_editada)
print(nao_foram_editados)
    
12.11.2018 / 18:31