Completing the task the 'proper' way

In task 22 of https://www.codecademy.com/courses/learn-python-3/projects/thread-shed, students are asked to iterate through the thread_sold_split list, comparing it to the colors list to see how many times an element in colors occurs in thread_sold_split.

The solution iterates through colors instead:

for color in colors:
  print('Today there were {0} {1} threads sold.'.format(color_count(color), color))

I was wondering how one would complete this task as prescribed, iterating through the thread_sold_split list?

Is your question asking if you can complete this task without calling the color_count function?

Color_count() already iterates through the thread_sold_split list. If you had the code just hanging outside the function it’d be rather inefficient (as you won’t always want to call for a count every time the program is run). But I might be misunderstanding the question!

Sorry if it wasn’t clear, I was wondering if it was possible to iterate through thread_sold_split instead of colors as the question asks. I was stuck up on trying doing that so I forgot you are already iterating through thread_sold_split by using color_count().

Thanks!

1 Like

No worries! I think that’s the point of this exercise, to get us tangled up.