简体   繁体   中英

Adding returned tuples to a list of lists

I am trying to add the returned tuples to a list of lists or list of arrays.

    dim = 10
    for key, figure in sorted(problem.figures.iteritems(), reverse=True):
        dim -= 1
        # print key, dim 
        (img_arr[dim], images[dim]) = vectorize(figure)

The function returns an array and an image. I am trying to create a list of arrays and a list of images. Can I do this without initializing a list of images outside of the loop?

img_arr[dim], images[dim] = vectorize(figure)

Try using append() attribute of list like this:

img_arr, images = [],[] # assuming you already declared the list

for key, figure in sorted(problem.figures.iteritems(), reverse=True):
     tup = vectorize(figure)
     img_arr.append(tup[0])
     images.append(tup[1])

The method append() appends a passed obj into the existing list.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM