0

Is there a way to merge two lists into one under one condition?

I have list of lists where I have name, email address and item purchased for each customer.

Some customers purchased two items and thus have the same email, but no name indicated as separate list.

How can I add their second purchased item into the first list with their names?

I have following:

['Heather Holt', 'ht*****r1011@gmail.com', 'Lite-Lounge - White']
['', 'ht*****r1011@gmail.com', 'Lite-Desk - Oyster Grey']

I want to see the lists in the following way:

['Heather Holt', 'ht*****r1011@gmail.com', 'Lite-Lounge - White', 'Lite-Desk - Oyster Grey']

Thanks for the hint.

1 Answers1

0

You should consider using dict to store your data. You could have a dict like

customer = { "name": "Heather Holt", "email": "ht*****r1011@gmail.com", products: ["Lite-Lounge - White"]

customer["products"].append("Lite-Desk - Oyster Grey")

print(customer["products"])

Output

["Lite-Lounge - White", "Lite-Desk - Oyster Grey"]
Challe
  • 599
  • 4
  • 19