When a list within a list is created and when it is removed--Thread Shed

Hi I am doing this exercise in python3 on a string. I am getting a bit confused between string and list. Can somebody explain when a list within a list is created and when it is removed?

(https://www.codecademy.com/courses/learn-python-3/projects/thread-shed)

daily_sales =
“”"Edith Mcbride ;,;$1.21 ;,; white ;,;
09/15/17 ,Herbert Tran ;,; $7.29;,;
white&blue;,; 09/15/17 ,Paul Clarke ;,;$12.52
;,; white&blue ;,; 09/15/17 ,Lucille Caldwell
;,; $5.13 ;,; white ;,; 09/15/17,

daily_sales_replaced=daily_sales.replace(";,;","<")

daily_transactions= daily_sales_replaced.split(",")
print(daily_transactions)
daily_transactions_split=[]
for sales in daily_transactions:
  daily_transactions_split.append(sales.split("<"))
print(daily_transactions_split)
transactions_clean=[]

for sales in daily_transactions_split:
  for sale in range (len(sales)):
    sales[sale]=sales[sale].strip()
  transactions_clean.append(sales)
'''
 why below removes the list within a list compared to above for loop
 transactions_clean = []
 for i in daily_transactions_split:
  for e in i:
   transactions_clean.append(e.strip()) 
'''

print(transactions_clean)
customers=[]
sales=[]
thread_sold=[]

for sale in transactions_clean:
  customers.append(sale[0])
  sales.append(sale[1])
  thread_sold.append(sale[2])
print(customers)
print(sales)
print(thread_sold)

total_sales=0
for sale in sales:
  total_sales+= float(sale.replace("$",""))
print(total_sales)

print(thread_sold)
# a list within a list is created here why ??? if so how do I remove it.
thread_sold_split=[]
for colour in thread_sold):
  if("&" in thread_sold[colour] == False):
    thread_sold_split.append(thread_sold[colour])
  else:
    thread_sold_split.append(thread_sold[colour].split("&"))
print(thread_sold_split)```

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