Code Review Stack Exchange is a question and answer site for peer programmer code reviews. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have produced a list of lists in Python of the form e.g.

track_list = [[3,1],[3,2],[3,3],[5,4],[5,8],[6,6],[8,1],[8,90]]

I would like to consider each given value in the first position and then select the lowest value in the second position. For the above, I would ideally like to get back the following:

[[3,1],[5,4],[6,6],[8,1]]

My attempted code is:

def mM(L):
x,y = zip(*L)
return (max(y))

for l in track_list:
        first_entry=l[0]
        for m in track_list:
            while m[0] == first_entry:
                second_entry = mM(track_list)

Is there any easy way to do this? I've been playing around with loops but have no idea how to focus on groups of the first element and am not really getting anywhere.

Any help would be most appreciated.

Thanks

share|improve this question

closed as off-topic by Peilonrayz, Mathias Ettinger, Nikita B, Graipher, forsvarir Jan 10 at 13:46

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions containing broken code or asking for advice about code not yet written are off-topic, as the code is not ready for review. After the question has been edited to contain working code, we will consider reopening it." – Peilonrayz, Mathias Ettinger, Nikita B, Graipher, forsvarir
If this question can be reworded to fit the rules in the help center, please edit the question.

3  
Welcome to Code Review. I'm afraid your question is off-topic as there is no code to review. Please go to the Help Center to understand how to ask a good question. – Stud Jan 10 at 13:03
    
I'm not a Python person, but you say that this is "attempted code". Does that mean that it doesn't work? That it works but it's slow? What? How have you tested it? This is no longer code not yet written, but it may still be broken code. It's somewhat Unclear what you're asking. – mdfst13 Jan 11 at 1:37
    
Yes it does not work. It produces the following error: – user11128 Jan 11 at 22:09

Browse other questions tagged or ask your own question.