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: customers.append(each) counter += 1 elif counter == 1: sales.append(each) counter += 1 elif counter == 2: thread_sold.append(each) counter += 1 elif counter == 3: counter = 0