Lists Project -Bellatrix Vault spell but with lists in Jupyter Notebook

I am currently doing my first project off platform on Jupyter Notebook. I am working on a lists project-(Frida_Project). This project asks you to append and zip lists together. I have come across an interesting problem where my zipped lists keep DOUBLING and I am pretty clueless.

paintings = ["The Two Fridas", "My Dress Hangs Here", "Tree of Hope", "Self Portrait With Monkeys"]

dates = [1939, 1933, 1946, 1940]

"""Zip together the two lists so that each painting is paired with its date and resave it to the paintings variable. Make sure to convert the zipped object into a list using the list() function. Print the results to the terminal to check your work."""

paintings = list(zip(paintings, dates))
print(paintings)
"""After running this, the "data" list doubles each time. I've even renamed the new list painting_2, same output.

[(((((((((((((((('The Two Fridas', 1939), 1939), 1939), 1939), 1939), 1939), 1939), 1939), 1939), 1939), 1939), 1939), 1939), 1939), 1939), 1939), (((((((((((((((('My Dress Hangs Here', 1933), 1933), 1933), 1933), 1933), 1933), 1933), 1933), 1933), 1933), 1933), 1933), 1933), 1933), 1933), 1933), (((((((((((((((('Tree of Hope', 1946), 1946), 1946), 1946), 1946), 1946), 1946), 1946), 1946), 1946), 1946), 1946), 1946), 1946), 1946), 1946), (((((((((((((((('Self Portrait With Monkeys', 1940), 1940), 1940), 1940), 1940), 1940), 1940), 1940), 1940), 1940), 1940), 1940), 1940), 1940), 1940), 1940)]"""

"""My solution was this bellow, the next question asked me to append a short list to the original.  I commented out the append portion to see if my while loop would clean up my list. 
 """"

new_list = ["The Broken Column", 1944, "The Wounded Deer", 1946, "Me and My Doll", 1937]
for i in new_list:
    while len(paintings)>15:
            paintings.pop()
    '''if len(paintings)< 15:
        paintings.append(i)'''
        
print(paintings)

"""The list does not double anymore but it isnt getting anf shorter.""""

Please help me, I am lost and hungry.

There’s no need to run that zipped list cell more than once. Because each time you do, well, you can see the results. .zip() is iterating over the two lists and creating nested tuples, then w/the addition of list(), which wraps the result of the (behind the scenes) for loop in brackets.

You can eliminate that by putting the two lists, paintings and dates in a different cell and then re-run that, then run the (different) cell w/the .zip() in it.

If I’m not mistaken, the instructions tell you to append the paintings separately…which would be more like:
paintings.append(('The Broken Column', 1944))

etc.

See the docs:

1 Like

Thank you, at first I was confused when you explained:

You can eliminate that by putting the two lists, paintings and dates in a different cell and then re-run that, then run the (different) cell w/the .zip() in it.

After I played around with the cells I understood and was able to complete the project.
I also reviewed the documentation linked at the bottom, its tough to read but I imagine it gets easier with time.

1 Like