Thread Shed, exercise 18

hellooo i have a question

why did i need two for loops?

thread_sold_split = []

for sale in thread_sold:

  for color in sale.split("&"):

    thread_sold_split.append(color)

print(thread_sold_split)

instead of use:

thread_sold_split = []

for sale in thread_sold:

  sale.split("&"):

    thread_sold_split.append(sale)

print(thread_sold_split)

there is no list inside thread_sold list because there is only one bracket in the output, so I don’t understand why two for loops instead of just one

We need both loops so we get a list of lists, not one long list. That will result in a loss of continuity since now all the data is mixed together. It is important to keep the data grouped.

2 Likes

thank you very much Roy!

1 Like