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
If it is multiple colors, first split the string around the
& character and then add each color individually to
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.append(thread.split('&')) print(color) else: thread_sold_split.append(thread) print(thread_sold_split) 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,