Frida Kahlo Retrospective Off-Platform Project - code review

Hi! I’m Dawid and i’m on 24% Data Scientist: Analytics. I’m from Poland and one funny fact about me : i’m lawyer and civil servant and now I have decided to become a data analyst :smiley:
Can someone check my code?

And for the end one question → why do I have to put +1 here? I don’t understand this :frowning:
audio_tour_number = list(range(1,paintings_length + 1))


paintings = ["The Two Fridas", "My Dress Hangs Here", "Tree of Hope", "Self Portrait With Monkeys"]
dates = [1939, 1933, 1946, 1940]
paintings = list(zip(paintings,dates))
print(list(paintings))
additional_paintings = [("The Broken Column", 1944), ("The Wounded Deer", 1946), ("Me and My Doll", 1937)]
paintings = paintings + additional_paintings
print(paintings)
paintings_length = len(paintings)
print(paintings_length)
audio_tour_number = list(range(1,paintings_length + 1))
print(audio_tour_number)
master_list = list(zip(audio_tour_number, paintings))
print(list(master_list))

In Python, range returns a sequence of numbers in which the starting number is included but the stop/end number is not included.

print(list(range(1, 5)))
# [1, 2, 3, 4]
# 1 is included but 5 is not included

print(list(range(4, 7)))
# [4, 5, 6]
# 4 is included but 7 is not included

print(list(range(3, 11, 2)))  
# [3, 5, 7, 9] (Step size of 2)
# 3 is included but 11 is not included

In the snippet of code you pasted, paintings is a list of 7 elements i.e. len(paintings) is 7.
If we did something like:

audio_tour_number = list(range(0, paintings_length))
# The result would be [0, 1, 2, 3, 4, 5, 6]

But in normal human conversation and communication, we usually list items starting from 1 instead of 0.
For Example

  1. Eggs
  2. Milk
  3. Bread
  4. Juice

instead of

  1. Eggs
  2. Milk
  3. Bread
  4. Juice

So instead of the sequence [0, 1, 2, 3, 4, 5, 6], we want to catalogue our paintings in the sequence [1, 2, 3, 4, 5, 6, 7] and consequently the statement:

audio_tour_number = list(range(1,paintings_length + 1))
# The result would be [1, 2, 3, 4, 5, 6, 7]
2 Likes

Now I get it! Thank you :slight_smile:

1 Like

Very helpful! I initially tried:

audio_tour_number = list(range(len(paintings)))
print(audio_tour_number)

but I couldn’t grok offsetting to start at 1. I didn’t realize that you could add +1 to a variable containing the value of len(paintings). Thanks!