Can someone explain to me why my code isn’t working? It seems to me it should and yet…
It comes from HERE (at point n. 10) in the ‘Learn Python 3’ course.
We have a list master_lst
containing sublists that each contain the TITLE, POET and DATE of famous poems.
And as you can read, we are asked to:
" write a for loop that uses .format()
to print out the following string for each poem:
The poem TITLE was published by POET in DATE.
"
master_lst = [['Afterimages', 'Audre Lorde', '1997'], ['The Shadow', 'William Carlos Williams', '1915'], ['Ecstasy', 'Gabriela Mistral', '1925'], ['Georgia Dusk', 'Jean Toomer', '1923'], ['Parting Before Daybreak', 'An Qi', '2014'], ['The Untold Want', 'Walt Whitman', '1871'], ["Mr. Grumpledump's Song", 'Shel Silverstein', '2004'], ['Angel Sound Mexico City', 'Carmen Boullosa', '2013'], ['In Love', 'Kamala Suraiyya', '1965'], ['Dream Variations', 'Langston Hughes', '1994'], ['Dreamwood', 'Adrienne Rich', '1987']]
string = "The poem {} was published by {} in {}"
for lst in master_lst:
string.format(lst[0], lst[1], lst[2])
print(string)