Search code examples
pythonrankingpreference

Ranking preference of each item in a list


I've been away from Python for awhile, please forgive the broad/basic question.

Let's say I have a list of items, which can be anything really.

I want to write a program that prints two of these at a time, in every possible combination of two, and lets the user choose a preference/winner. Then at the end print the full list with some sort of numerical preference value for each. I don't know enough about the mathematics of rank or preference to know what that number would even look like...

Basically I'm having writer's block right from the start here. Any advice on how to structure this or what I should be looking into?


Solution

  • A very simple way of doing it would look something like this:

    initialize a scoring_list
    
    for every element in a list
        for every element in a list
    
            while valid input:
                ask the question via raw_input()
    
                if input matches the first item
                    store winner in some sort of scoring list
                    tell program input is valid
    
                else if input matches the second item
                    store winner in some sort of scoring list
                    tell program input is valid
    
                else
                    tell program input is not valid and repeat question
    
    do some math with the scoring_list (e.g. normalization)
    print( scoring_list )
    

    Obviously a lot of detail is left out intentionally, because it depends on programming style and objectives. For example, it may be better to do the loops via indices so that you can have a scoring list with indices that matches your original list. With this structure, you can be creative with how you are tracking the "ranks" with something more statistically rigorous than a straight count.