Why am i getting double nested list

Preformatted textI have this list that i should clean but every time i run (code 1) below it give me double nested list tell me what i am doing wrong please.
,
daily_transactions_split = [['Nuggets Mcbride ', '$1.21 ', ’ white ', ’ \n09/15/17 '], [‘Herbert Trando ‘, ’ $7.29’, ’ \nwhite&blue’, ’ 09/15/17 '], ['Pauli Clarkem ', ‘$12.52 \n’, ’ white&blue ', ’ 09/15/17 '], [‘Luciille Jaldwell \n’, ’ $5.13 ', ’ red ‘, ’ 09/15/17’]]
,

,
code 1
transactions_clean =

for transaction in daily_transactions_split:
    transaction_clean = []
    for data_point in transaction:
        transaction_clean.append(data_point.strip(""))
        transactions_clean.append(transaction_clean)
        
print(transactions_clean)

,

answer:
[['Edith Mcbride ', '$1.21 ', ’ white ', ’ \n09/15/17 '], ['Edith Mcbride ', '$1.21 ', ’ white ', ’ \n09/15/17 '], ['Edith Mcbride ', '$1.21 ', ’ white ', ’ \n09/15/17 '], ['Edith Mcbride ', '$1.21 ', ’ white ', ’ \n09/15/17 '], [‘Herbert Tran ‘, ’ $7.29’, ’ \nwhite&blue’, ’ 09/15/17 '], [‘Herbert Tran ‘, ’ $7.29’, ’ \nwhite&blue’, ’ 09/15/17 '], [‘Herbert Tran ‘, ’ $7.29’, ’ \nwhite&blue’, ’ 09/15/17 '], [‘Herbert Tran ‘, ’ $7.29’, ’ \nwhite&blue’, ’ 09/15/17 '], ['Paul Clarke ', ‘$12.52 \n’, ’ white&blue ', ’ 09/15/17 '], ['Paul Clarke ', ‘$12.52 \n’, ’ white&blue ', ’ 09/15/17 '], ['Paul Clarke ', ‘$12.52 \n’, ’ white&blue ', ’ 09/15/17 '], ['Paul Clarke ', ‘$12.52 \n’, ’ white&blue ', ’ 09/15/17 '], [‘Lucille Caldwell \n’, ’ $5.13 ', ’ white ‘, ’ 09/15/17’], [‘Lucille Caldwell \n’, ’ $5.13 ', ’ white ‘, ’ 09/15/17’], [‘Lucille Caldwell \n’, ’ $5.13 ', ’ white ‘, ’ 09/15/17’], [‘Lucille Caldwell \n’, ’ $5.13 ', ’ white ‘, ’ 09/15/17’]]

double check your indentation here:

transactions_clean.append(transaction_clean)

The way you have it written you’re cleaning, appending and the appending again, which would give you duplicates.

You would also be able to find answers here:
https://discuss.codecademy.com/search?q=thread%20shed%20step%208

1 Like

I believe i was suppose to return
transactions_clean.append(transaction_clean) to the first for loop which is transaction . is that correct ?

transactions_clean = []
for transaction in daily_transactions_split:
    transaction_clean = []
    for data_point in transaction:
        transaction_clean.append(data_point.strip(""))
        
    transactions_clean.append(transaction_clean)
        
print(transactions_clean)

its ok when you told me its an indentation problem i saw what i was doing wrong thank you :heart_eyes:

1 Like