for thread in thread_sold:
for color in thread.split("&"):
thread_sold_split.append(color)
What about the solution given by codeacademy? I thought it would return the individual letters (“w”, “h”, …) given the double for loop but it magically returns the whole words (white, blue, …)
How come if we append(color) it returns the whole words?
i tried list comprehension in step 9 like this: titles, poets, dates = [poem[0], poem[1], poem[2] for poem in highlighted_poems_details]
this didn’t work. is there a way how it would have worked?
Can someone explain this code to me? I’m not sure why when we append those lists why we need to use the index numbers. Or where they even came from. I also don’t fully understand the second for statement. I am new to python, it’s only my second week coding. I’m sorry if I sound stupid.
for poem in highlighted_poems_details:
titles.append(poem[0])
poets.append(poem[1])
dates.append(poem[2])
for i in range(0,len(highlighted_poems_details)):
print(‘The poem {} was published by {} in {}’.format(titles[i], poets[i], dates[i]))
We have composed a list for each poem. Each list has three elements that correspond to title, poet and date in that order. It means that each poem above in said list of three elements. The code extracts each element and appends to the corresponding list.
Python permits unpacking of list objects.
title, poet, date = poem
titles.append(title)
poets.append(poet)
dates.append(date)
which amounts to the same thing, without need of indexing. This doesn’t mean we toss the code you’ve shown. Both approaches are valid.
for i in range(0,len(titles)):
return print(“The poem {title} was published by {poet} in {date}”.format(title, poet, date = titles[i], poets[i], dates[i]))
but I keep getting an error: “SyntaxError: positional argument follows keyword argument”
for poem in highlighted_poems_details:
titles.append(poem[0])
poets.append(poem[1])
dates.append(poem[2])
for poem in highlighted_poems_details:
msg = “The poem {titles[0]} was punlished by {poets[0]} in {dates[0]}”
return msg
Return cannot be used outside a function. You don’t need to return anything from a loop. It’s just a quick way to repeat statements of code.
If you’re submitting a query on code to the forums pease try to format it. It makes things easier to debug. You can format code using a triple backquote/accent grave character `
For example…
` ` `
x = 3
` ` `
becomes
Man I also have same problem. I am very new too and also did not quite understand the loop series. although I understood this problem pretty much. You should check some youtube vid for each series. That may help.