Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
3 Risposte
6810 Visualizzazioni

here is my python list when i debug it

list: [[4, 1, False], [4, 2, False], [4, 3, False], [4, 4, False], [4, 5, False]]

now i need to convert it to this type list

list: [1,2,3,4,5]

please advice me to implement this.

Avatar
Abbandona
Risposta migliore

Why not use a one-liner?

>>> source = [[4, 1, False], [4, 2, False], [4, 3, False], [4, 4, False], [4, 5, False]]
>>> result = [x[1] for x in source]
>>> print result
[1, 2, 3, 4, 5]
Avatar
Abbandona

intelligent ! but for the visibility of code .!!

Autore

thanks dear Daniel..seems its more easier :-)

Risposta migliore

hey priyanka do one think :

 list=[[4, 1, False], [4, 2, False], [4, 3, False], [4, 4, False], [4, 5, False]]
 m=[]
 for i in range(0,len(list)):
     m.extend(list[0])
 m=[4, 1, False, 4, 2, False, 4, 3, False, 4, 4, False, 4, 5, False]

thanks

Avatar
Abbandona
Risposta migliore

Hi;

list= [[4, 1, False], [4, 2, False], [4, 3, False], [4, 4, False], [4, 5, False]]      
my_list=[]
for object in list : 
    my_list.append(object[1])


print my_list # give [1, 2, 3, 4, 5]
Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
0
mar 25
1181
4
apr 24
173782
0
dic 23
1962
5
lug 25
226957
1
dic 22
3011