python - How to get values from lists of lists and add them to smaller lists -


say have lists so:

mylist1 = [1,2,3] mylist2 = [7,8,9] mylist3 = [13,14,15] 

and append them larger list:

mybiglist = [] mybiglist.append(mylist1) mybiglist.append(mylist2) mybiglist.append(mylist3) 

and have smaller lists such:

a = [] b = [] c = [] 

how iterate through 'mybiglist' list, , pull out first value of smaller lists , store values in a, second values of shorter lists, in b, , shorter of third in c? appreciate help.

zip great.

>>> mylist1 = [1,2,3] >>> mylist2 = [7,8,9] >>> mylist3 = [13,14,15] >>> mybiglist = [] >>> mybiglist.append(mylist1) >>> mybiglist.append(mylist2) >>> mybiglist.append(mylist3) >>> mybiglist [[1, 2, 3], [7, 8, 9], [13, 14, 15]] >>> a, b, c = zip(*mybiglist) >>> (1, 7, 13) >>> b (2, 8, 14) >>> c (3, 9, 15) 

are using mybiglist something? if want, can arrive @ a, b, , c without putting them mybiglist @ all.

>>> a, b, c = zip(mylist1, mylist2, mylist3) >>> (1, 7, 13) >>> b (2, 8, 14) >>> c (3, 9, 15) 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -