20/20 Lab <l...@pacbell.net> writes: > I'm a beginner to python. Reading here and there. Written a couple of > short and simple programs to make life easier around the office.
Welcome, and congratulations on self-educating to this point. > myList = [ [123, "XXX", "Item", "Qty", "Noise"], > [72976, "YYY", "Item", "Qty", "Noise"], > [123, "XXX" "ItemTypo", "Qty", "Noise"] ] > > Basically, I need to check for rows with duplicate accounts row[0] and > staff (row[1]), and if so, remove that row, and add it's Qty to the > original row. I really dont have a clue how to go about this. You might benefit from doing some simple study of algorithms, with exercises so you can test your knowledge and learn new ways of thinking about basic algorithms. I say that because what will be most helpful in the situation you're facing is to *already* have learned to think about already-solved algorithms like a toolkit. And the only way to get that toolkit is to do some study, rather than solving each problem in the real world as it comes along. In this case, you are stuck IMO because the process you want to perform on the data needs to be formally expressed. Here's an attempt: For each unique pair (‘account_nr’, ‘staff_name’): Sum all the ‘qty’ values as ‘total_qty’ Emit a record (‘account_nr’, ‘staff_name’, ‘total_qty’) Once expressed that way, it becomes clear to me that the requirements as stated have a gap. What becomes of ‘item’, ‘noise’, etc. values for the same (‘account_nr’, ‘staff_name’) pair? Are they simply discarded as uninteresting? If not discarded, how are they processed to make a single record for that (‘account_nr’, ‘staff_name’) pair? You don't have to respond to me with the answers. But you will need to deal with that issue, and probably others. The advantage of formally stating the process you want is to debug it before even writing a line of code to solve it. Here is a course on problem solving with algorithms that uses Python <URL:http://interactivepython.org/runestone/static/pythonds/index.html>. Good hunting! -- \ “We cannot solve our problems with the same thinking we used | `\ when we created them.” —Albert Einstein | _o__) | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list