I have a Python problem that can be solved with multiple nested for
loops but I was wondering if there is an easier way to solve this, maybe by adding list items together and dropping duplicates.
My list looks like this:
main_list = [["user1@test.com", "Administration", "100"],
["user2@test.com", "Testing", "30"],
["user2@test.com", "Development", "45"],
["user2@test.com", "Development", "90"],
["user2@test.com", "Development", "35"],
["user3@test.com", "Development", "400"],
["user3@test.com", "Administration", "95"],
["user3@test.com", "Testing", "200"]]
I need to merge the email address and category (the first two list elements) and add the duplicate 3rd entries together.
So [user2, development] goes from:
["user2@test.com", "Development", "45"],
["user2@test.com", "Development", "90"],
["user2@test.com", "Development", "35"],
to:
["user2@test.com", "Development", "170"]
It this possible with list manipulation?
Thank you!