Filter a specific element within a stripe within another list [duplicate]

0

I have a filter to find the index of a stripe inside another list (I found in the group author Anderson Carlos)

fila = [['vitor','5'], ['vitor', '4']]

def sdb(filadb,nome,elemento):

if not (filadb):
    return None
else:
    filadb_l = filadb[0]
    p = [(filadb_l.index(x), x.index(nome)) for x in filadb_l if nome in x] # linha 0 posicao 1
    if p == []:
        return None
    else:
        p_e = [(fila_pe.index(x), x.index(elemento)) for x in fila_pe if elemento in x] # linha 0 posicao 1
        p_linha = filadb_l[p[0][0]]
        posicao_e = fila_pe[p_e[0][0]][1]       
        p_elemento = p_linha[posicao_e]
        result = [p_linha]
        return p_elemento

function return:

  
    
      

[5]       That way I have only one element.

    
  

I wanted to get back the 2 elements. return:

  
    
      

['5', '4']

    
  
    
asked by anonymous 06.04.2018 / 04:17

1 answer

1
filaa = [(('vitor','5'), ('vitor', '4'))]
def sadb(filadb,nome):
    l = []
    if not (filadb):
        return None
    else:
        filadb_l = filadb[0]
        p = [(filadb_l.index(x), x.index(nome)) for x in filadb_l if nome in x] # linha 0 posicao 1
        if p == []:
            return None
        else:
            for item in p:
                lista = filadb[0][item[0]]
                n = lista[1]
                if not 'valvula' in l:
                    l.append(n)
            return l

print sadb(filaa, 'vitor')
  
    
      

['5', '4']

    
  

The code is not optimized, but it works fine.

    
06.04.2018 / 20:38