Python Sorting and Organising
Question: I'm trying to sort data from a file and not quiet getting what i need. I have
a text file with race details ( name placement( ie 1,2,3). I would like to be
able to organize the data by highest placement first and also alphabetically
by name. I can do this if i split the lines but then the name and score will
not match up.

Any help and suggestion would be very welcomed, I've hit that proverbial wall.

My apologies ( first time user for this site , and python noob, steep learning
curve ) Thank you for your suggestions , i really do appreciate the help.

    
    
    comp=[]
    
    results = open('d:\\test.txt', 'r')
    
    
    for line in results:
        line=line.split()
        # (name,score)= line.split()
        comp.append(line)
        sorted(comp)
    
    results.close()
    print (comp)
    

Test file was in this format:  
Jones 2  
Ranfel 7  
Peterson 5  
Smith 1  
Simons 9  
Roberts 4  
McDonald 3  
Rogers 6  
Elliks 8  
Helm 10


Answer: I completely agree with everyone who has down-voted this question for being
badly posed. However, I'm in a good mood so I'll try and at least steer you in
the right direction:

Let's assume your text file looks like this:

    
    
    Name,Placement
    D,1
    D,2
    C,1
    C,3
    B,1
    B,3
    A,1
    A,4
    

I suggest importing the data and sorting it using Pandas
<http://pandas.pydata.org/>

    
    
    import pandas as pd
    
    # Read in the data
    # Replace <FULL_PATH_OF FILE> with something like C:/Data/RaceDetails.csv
    # The first row is automatically used for column names
    data=pd.read_csv("<FULL_PATH_OF_FILE>")
    
    # Sort the data
    sorted_data=data.sort(['Placement','Name'])
    
    # Create a re-indexed data frame if you so desire
    sorted_data_new_index=sorted_data.reset_index(drop=True)
    

This gives me:

    
    
    Name Placement
    A    1
    B    1
    C    1
    D    1
    D    2 
    B    3
    C    3
    A    4
    

I'll leave you to figure out the rest..

