Hi All!
This is my first question here on the forums, I’m in the middle of the Thread Shed challenenge, I can’t seem to get rid of the whitespace from my lists, I followed the guide, searched the forums, and even went on Stackoverflow, no joy
transactions_clean = []
for transaction in daily_transactions_split:
transaction_clean=[]
for data_point in transaction:
transaction_clean.append(data_point.replace("\n", " ").strip(" "))
transactions_clean.append(transaction_clean)
print(transactions_clean)
Hi midlindner!
I did try that to be honest, I even tried .lstrip() .rstrip() with quotations and without. Whenever I print the results they have whitespace on either side which doesn’t seem to fix the problem.
I must be missing something, but I can’t see it.
For reference the project is here. It will be helpful if you post all of your code. You can leave the lengthy daily_sales variable out.
Edit: I ran your code snippet in place of my own with my remaining code, and it works as expected. Your issue would seem to be in the code prior to what you’ve posted that generates daily_transactions_split.
I think I figured out how to sort this out, this is the problem code. You were right I had to go and write up the code all again to find the smallest problem.
Thank you midlindner
daily_sales_replaced = daily_sales.replace(';,;', ',')
daily_transactions = daily_sales_replaced.split(",")
#print(daily_transactions)
daily_transactions_split = []
for transaction in daily_transactions:
daily_transactions_split.append(transaction.split(';'))
transactions_clean = []
for transaction in daily_transactions_split:
transaction_clean=[]
for data_point in transaction:
transaction_clean.append(data_point.replace("\n", " ").strip(""))
transactions_clean.append(transaction_clean)
print(transactions_clean)
customers = []
sales = []
thread_sold = []
and this is after the fix:
daily_sales_replaced = daily_sales.replace(';,;', ' ; ')
daily_transactions = daily_sales_replaced.split(",")
#print(daily_transactions)
daily_transactions_split = []
for transaction in daily_transactions:
daily_transactions_split.append(transaction.split(';'))
#print(daily_transactions_split)
transactions_clean = []
for transaction in daily_transactions_split:
transaction_clean=[]
for data_point in transaction:
transaction_clean.append(data_point.replace("\n", " ").strip(" "))
transactions_clean.append(transaction_clean)
print(transactions_clean)
customers = []
sales = []
thread_sold = []