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:
transactions_clean.append(item.strip())

print(transactions_clean)

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…

customer:sale:thread_sold

…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…

customers.append(item.split(":")[0])

Hope this helps.

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