How to add to a list but so it is every ___ index number in a list?

transactions_clean =

for small_list in daily_transactions_split:
for item in small_list:


customers =
sales =
thread_sold =

for item in transactions_clean:
customers.append(item[0]???). ------ **problem is somewhere here I know **

I am trying to add to the lists customers, sales, and threads sold and each item in the list “transactions_clean” have these three things but I need to be able to add every third item to the list and I dont know how to do this?

Thanks in advance

Hi there!

If you know what format each item will be in, this is fairly straightforward… You can split by a delimiter (something like a comma or a colon placed between values to separate them) and then select which index of this newly created list you want.

So, for example, if each item is in format…


…calling item.split(":")[0] would give you the customer, item.split(":")[1] the sale, and item.split(":")[2] the thread_sold.

So, given the above example, if you want to add the current customer to the customers list…


Hope this helps.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.