Returning a certain list structure in Python -


i'm having trouble list (and list of list, , list of list of lt...) structures.

use t += instead of .append() operator. , use second list temp

new_list = [] sublist in lines:     temp = []     word in sublist:         temp+=key_to_phonemes[word]     new_list.append(temp) 

edit:

new_list = [] n,sublist in enumerate(lines):     new_list.append([])     word in sublist:         new_list[n]+=key_to_phonemes[word] 

is better saves making temp

endedit

the behavioural difference here follows.

[ 1 , 2 , 3 ].append( [ 4 , 5 ] )

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

vs.

[ 1 , 2 , 3 ]+[ 4 , 5 ]

[ 1 , 2 , 3 , 4 , 5 ] 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -