Hello! Programming newbie here. I am working through the Computer Science pathway. I am currently trying to complete the Thread Shed project in the Python: Strings module, however I am having a bit of trouble. I’ve copied my code below.
Whenever I print the lists I’ve created (customer, sale, and thread_sold) to the console, I get 4 instances of on piece of data.
For example:
customers = [[‘Edith Mcbride’, ‘Edith Mcbride’, ‘Edith Mcbride’, ‘Edith Mcbride’, ‘Herbert Tran’, ‘Herbert Tran’, ‘Herbert Tran’, ‘Herbert Tran’, ‘Paul Clarke’, ‘Paul Clarke’, ‘Paul Clarke’, ‘Paul Clarke’, ‘Lucille Caldwell’, ‘Lucille Caldwell’, ‘Lucille Caldwell’, ‘Lucille Caldwell’,… and so on]
I’ve been going over my code and I can’t seem to understand why this is happening. Is there anyone who knows why I’m getting this output?
daily_sales_replaced = daily_sales.replace(';,;','|')
daily_transactions = daily_sales_replaced.split(',')
daily_transactions_split = []
for transaction in daily_transactions:
daily_transactions_split.append(transaction.split('|'))
#print(daily_transactions_split)
transaction_clean = []
for transaction in daily_transactions_split:
transaction_cleaner = []
for data in transaction:
transaction_cleaner.append(data.replace('\n', ' ').strip(' '))
transaction_clean.append(transaction_cleaner)
customers = []
sale = []
thread_sold = []
for transaction in transaction_clean:
customers.append(transaction[0])
sale.append(transaction[1])
thread_sold.append(transaction[2])
print(customers)
print(sale)
print(thread_sold)