Hello
I am trying to solve this project about python string. Learn Python 3 | Codecademy
I am stuck on task 8 The question asks to make two for loops which loops through the data_points to remove the whitespace. I have tried to copy the code using the get unstuck video but I am getting each list 3 or four times, below is my code.
when I try to make my own code i do remove the whitespaces but the list becomes one list which will not work for the next tasks.
below is my own code
aily_sales_replaced = daily_sales.replace(";,;","+")
daily_transactions = daily_sales_replaced.split(",")
#print(daily_transactions)
daily_transactions_split = []
for transactions in daily_transactions:
daily_transactions_split.append(transactions.split("+"))
#print(daily_transactions_split)
transactions_clean = []
for transaction in daily_transactions_split:
for data_point in transaction:
transactions_clean.append(data_point.strip(" "))
print(transactions_clean)
i get a one list with the whitespaces removed but cant make the further tasks work as I cant split the data to other lists.
below is the code by the help video, I used it but it would give a list multiple time.
daily_sales_replaced = daily_sales.replace(";,;","+")
daily_transactions = daily_sales_replaced.split(",")
#print(daily_transactions)
daily_transactions_split = []
for transactions in daily_transactions:
daily_transactions_split.append(transactions.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(","," ").strip(" "))
transactions_clean.append(transaction_clean)
print(transactions_clean)
what is a proposed solution to solve this task