Tuples and Lists



I have a list of tuples in the variable tups_list, each tuple of which contains 2 strings and a list. I am trying to create a list of Photo instances, where each Photo instance uses the data from each tuple in the tups_list and save that list in a variable photo_insts.

photo_instances = []
tups_list = [("Portrait 2","Gordon Parks",["chicago", "society"]),("Children in School","Dorothea Lange",["children","school","1930s"]),("Airplanes","Margaret Bourke-White",["war","sky","landscape"])]
for i in tups_list:
        photo_instances = (i[0],i[1],i[2])
        print i

current error: AttributeError: 'tuple' object has no attribute 'append'....I understand the error but I am not sure how to fix it. Any help would be great.


you have a list:

photo_instances = []

and tuple:

photo_instances = (i[0],i[1],i[2])

which have the same name, i think you need to rename the tuple:

photo_tuple = (i[0],i[1],i[2])


Great that makes sense!


because you overwrote your list with a tuple, then you try to append a tuple to a tuple (which gives an error message since you can't append to tuples)