Filter list of lists

Asked

Viewed 81 times

0

Hello! You have to separate elements from a list of lists, without repeating them?

Example: From the pre list, modifying the test condition to validate the combinations if their sum was a multiple of 5.

Lista_pre = [6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]

list generated from the list, using magic square code, for an output condition-->sum(list)%5 = 0,class=2. That is, the sum of the combined elements of the pre list will always be a multiple of 5, in this particular case. I produce the original list, which I need to separate without repeating elements:

lista_original = [[6 , 9],[6 ,14],[6 , 19], [6 , 24], [7 , 8],[7, 13] ,
                    [7 ,18],[7 ,23],[8 , 12], [8 , 17], [8 ,22],[9, 11] ,
                    [9 ,16],[9 ,21],[10, 15], [10, 20], [11,14],[11,19] ,
                    [11,24],[12,13],[12, 18], [12, 23], [13,17],[13, 22],
                    [14,16],[14,21],[15, 20], [16, 19], [16,24],[17, 18],
                    [17,23],[18,22],[19, 21], [21, 24], [22,23]]

Expected final result:

nova_lista1 = [[6,  9],[7,  8],[10,15],[12,13],[14,16],[17,18],[19,21], [22,23]]
nova_lista2 = [[6, 14],[7, 13],[8, 12],[9, 11],[10,20],[16,19],[17,23],[18,22],[21,24]
nova_lista3 = [[6, 19],[7, 18],[8, 17],[9, 16],[11,14],[15,20]]
nova_lista4 = [[6, 24],[7, 23],[8, 22],[9, 21],[11,19],[12,18],[13,17]]
nova_lista5 = [[11,24],[12,23],[13,22],[14,21]]
nova_lista6 = [[16,24]]

In none of the new listings there will be repeated elements:

It will be using in a survey I define as Qm(n) or Modulatory Table of the integer n, where, the coefficients calculated in the new lists, natural of a certain number n. There is no rule of size for any of the lists: Size of the list_pre = 19----->variable by nature as a function of the value of n. Size of the original list = 35----->variable depending on the combinatorial class used. Size of novas_lists vary depending on the combinatory model applied to the pre list, derived from the model of possible combinations to arrive at a proposed result, covered in the magic square programming. Then the code will have to scan the positions of the original list, without repeating elements in each generated new_list.

You can help me,!?

lista_saida = []
i = 0
lista=[[6,9],[6,14],[6,19],[6,24],[7,8],[7,13],[7,18],[7,23],[8,12],[8,17],[8,22],[9,11],[9,16],[9,21],[10,15],[10,20],[11,14],[11,19],[11,24],[12,13],[12,18],[12,23],[13,17],[13,22],[14,16],[14,21],[15,20],[16,19],[16,24],[17,18],[17,23],[18,22],[19,21],[21,24],[22,23]]
lista_saida.append(lista[0])  #Define  valor inicial de lista_saida
for x in range((1+i),len(lista)):#Atualiza início de busca até limite da lista
    for y in range(len(lista_saida)):#Procura elementos da lista_saida que estejam na lista,para não adotá-los
    if lista_saida[y][0]!=lista[x][0] and lista_saida[y][0]!=lista[x][1] and lista_saida[y][1]!=lista[x][0] and lista_saida[y][1]!=lista[x][1]:#Verifica índices
               lista_saida.append(lista[x])
        i+=1

From the pile burst

  • Put a little bit of the code, showing what you’ve tried to do, and how you’re organizing the data entry. It’s in Python, isn’t it? Mark the language you are using in the tags as well.

  • Here you only have comments - arrange your question as requested and you may have a quality answer.

  • Unfortunately the append list method,is not accumulator so even if you can separate non-repeating elements, every new element selected the list loses the previously selected element, tried using dial,gave anyway,so I did the following:I will separate the 1 element of the entry list and what remains of this pre-filtered list will be possible combinatorial models for associations .

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.