python - Substracting the last element form a list of lists -


i need subtract last element , buid vector [1,1,1,...]. have function:

def vectores(lista):     r=[]     e in lista:         r.append(e[2])         return r 

where

lista = [['pintor', 'ncms000', 1], ['ser', 'vsis3s0', 1], ['muralista', 'aq0cs0', 1], ['diego_rivera', 'np00000', 1], ['frida_kahlo', 'np00000', 1], ['caso', 'ncms000', 1]] 

but function returning [1]; can do?

you're returning on first iteration of loop. move return statement outside for-loop:

def vectores(lista):     r=[]     e in lista:         r.append(e[2])     return r  # here 

or use list comprehension:

def vectores(lista):     return [e[2] e in lista] 

Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -