How can we reference the right index if all our lists are seperate?

yea, when is a keyword there, if computers worked at less than light speed that will take forever to finish

for question no.10, is my code okay or is it better to use the solutions one? i need some sort of code review

my code:

for detail in highlighted_poems_details:
  print("The poem {title} was published by {poet} in {date}"
        .format(title=detail[0], poet=detail[1], date=detail[2]))


for i in range(0,len(highlighted_poems_details)):
    print('The poem {} was published by {} in {}'.
           format(titles[i], poets[i], dates[i]))

There is nothing wrong with your code, though I would say that using keywords is overkill unless your want the order in the output to be changed up some how. Format keywords are not positional, meaning their order doesn’t matter.

In the solution code it looks like the author has already created the three lists suggested so there are four lists of the same length. Any one of them could have been referred in the signature line.

for i in range(len(titles)):

would give the same range.

As this is an old lesson, it may have predated the release of the new f-string, which takes variables and expressions directly:

for title, poet, date in highlighted_poems_details:
    print (f"The poem {title} was published by {poet} in {date}")
#          ^
#          |
#    f-string operator

As for the solution, if that is what is expected, meaning your solution was not, then we should go along with it. If any solution is accepted, assuming it gives the correct output, then use what you feel most comfortable with.


thank you very much sirr

1 Like
length = len(titles)
for i in range(length):
  poem_details = "The poem {} was published by {} in {}".format(titles[i], poets[i], dates[i])

I saw a lot of unique solutions on this thread already but I wanted to add mine because it took me some frustration to figure it out. I referenced the index of the corresponding list item inside of the format string method.