Pythonic Approach to Thread Shep Project Step 11

I just got done with the Thread Shed Project, but can’t help to think that I tackled a task a bit too inefficiently. In step 11 we’re asked to append pieces of string data from a list (“transactions_clean” list) into various other lists (“customers”, “sales”, “thread_sold”).

Because of their consistent order, I used a counter variable that would reset and help with selecting which list to append to.

So is this as efficient and pythonic as could be expected or is this excessive?

Copy of my code:

  • Section in question starts at line 126

Project: Learn Python 3 | Codecademy

customers = []
sales = []
thread_sold = []

counter = 0   #was this really needed?

for each in transactions_clean:
  if counter == 0:
    counter += 1
  elif counter == 1:
    counter += 1
  elif counter == 2:
    counter += 1
  elif counter == 3:
    counter = 0

Be sure to Share your workspace or we get a 404.

1 Like

When we print transactions_clean (at line 125) we get one homogeneous list, rather than a list of lists, so individual sales data is now lost. My view is that the list should be a list of lists.