Frida Kahlo Assignment

And here I am, ready to be butchered! :slight_smile:

Anyone giving any useful insight is very welcome!

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

dates = [1939, 1933, 1946, 1940]

#Zipping the two lists into one

paintings = list(zip(paintings, dates))

#Appending some more paintings to the list

paintings.append(('The Broken Column', 1944))

paintings.append(('The Wounded Deer', 1946))

paintings.append(('Me and My Doll', 1937))

#Checking how many painting we are worlking with

print("There are", len(paintings),"paintings")

#Generating list of audio tour number for each painting

audio_tour_number = [num + 1 for num in range(len(paintings))]

#Wrapping it all up and checking the final list

master_list = list(zip(paintings, audio_tour_number))

print(master_list)

Which outputs:

There are 7 paintings
[(('The Two Fridas', 1939), 1), (('My Dress Hangs Here', 1933), 2), (('Tre of Hope', 1946), 3), (('Self Portrait With Monkeys', 1940), 4), (('The Broken Column', 1944), 5), (('The Wounded Deer', 1946), 6), (('Me and My Doll', 1937), 7)]

Please format your code…using the </> button.

Also, what’s the results of the print() statements? (include those as well)

Done, and done. Thank you!

1 Like
  • An easier(?) way to do the audio part:
audio_tour_number = list(range(1, 8))
print(audio_tour_number)

>>[1, 2, 3, 4, 5, 6, 7]
  • I think the audio tour number is supposed to go first. Also, I thought they were individual lists within a list?

ex:

master_list = list(zip(audio_tour_number, paintings))

print(master_list)
>>> [[1, ('The Two Fridas', 1939)], [2, ('My Dress Hangs Here', 1933)], [3, ('Tree of Hope', 1946)], [4, ('Self Portrait With Monkeys', 1940)], [5, ('The Broken Column', 1944)], [6, ('The Wounded Deer', 1946)], [7, ('Me and My Doll', 1937)]]

  • also, if you run this bit of code more than once, b/c it iterates over the zipped items each time --and returns an iterator of tuples–you’ll get tuples within tuples, within tuples…infinity. Even if you wrap it in list().
paintings = list(zip(paintings, dates))
print(paintings)

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

which I think is why you have two sets of parens, surrounded by brackets at the end.

Alternatively, to nix the tuples, you could rerun the cells that have the two lists, paintings and dates and then run a list comprehension if you want:

paintings = [list(x) for x in zip(paintings, dates)]
print(paintings)
>>>[['The Two Fridas', 1939], ['My Dress Hangs Here', 1933], ['Tree of Hope', 1946], ['Self Portrait With Monkeys', 1940]]

And then, when you combine the audio tour numbers w/the final list of paintings, do another list comprehension,

master_list = [list(x) for x in zip(audio_tour_number, paintings)]
print(master_list)
>>[[1, ['The Two Fridas', 1939]], [2, ['My Dress Hangs Here', 1933]], [3, ['Tree of Hope', 1946]], [4, ['Self Portrait With Monkeys', 1940]], [5, ('The Broken Column', 1944)], [6, ('The Wounded Deer', 1946)], [7, ('Me and My Doll', 1937)]]

But, tbh it’s been so long since I did this, I can’t recall if they even want you to use a list comprehension and just keep the tuples. :woman_shrugging:

They actually teach list comprehensions and your observations are spot on and interesting. Thank you.

1 Like