https://www.codecademy.com/courses/learn-python-3/projects/thread-shed
I was able to figure out everything up to #18, however I can’t figure out how to work on #19.
- Great, now we have a list
thread_sold_split
that contains an entry with the color of every thread sold today.
Define a function called color_count
that takes one argument, color
. The function should iterate through thread_sold_split
and count the number of times the item is equal to argument, color
. Then, it should return this count.
- Test your new function by running
color_count('white')
.
Your function should return 28
.
here is my code.
for color in thread_sold:
if “&” not in color:
thread_sold_split.append(color)
else:
thread_sold_split.append(color.split(“&”))
def color_count(color):
count = 0
for thread in thread_sold_split:
for c in thread:
if c == color:
count +=1
return count
print(color_count(‘white’))
why is my output 22 instead of 26 ??? can anyone explain?