Thread Shed step 18

Hi there,

Here’s what the exercise is asking:

Next, iterate through thread_sold. For each item, check if it is a single color or multiple colors. If it is a
single color, append that color to thread_sold_split .

If it is multiple colors, first split the string around the & character and then add each color individually to thread_sold_split

I used this code that it’s not working. It prints the same words. I added the list --> dict --> list conversion since it prints out duplicates.

Here’s the code:

for thread in thread_sold_stripped:
  for color in (0,len(thread)):
    if(color == '&'):


thread_sold_split = list(dict.fromkeys(thread_sold_split))

I was watching the walkthrough and I saw he uses split directly in the for loop. I didn’t know it was possible actually, but is there any way to make my code work?

Thanks a lot,

1 Like

Hi there.

I think you’re missing something from your inner for loop… for color in (0, len(thread)) will execute twice; once for each item in the tuple.

I think your if condition is also wrong, because I don’t see how / why you’d have a color which is just an ampersand on it’s own… but I haven’t done the Thread Shed project so this is a guess.

1 Like