210-6 Winning Jeopardy

I completed the Winning Jeopardy guided project. However, I’m getting a different result from the one in the solution book on the part, where we develop a count_usage and determine_value function. I looked at the solution book and copy-pasted the code on there. However, I still get a different result. I want to understand why I’m getting a different result than the one in the solution book, even though I ran the same code.

My result:

[(0, 1), (1, 0), (1, 4), (0, 2), (0, 1)]

Solution key:

[(2, 4), (0, 1), (4, 0), (1, 0), (0, 1)]

Solution key code

def count_usage(term):
    low_count = 0
    high_count = 0
    for i, row in jeopardy.iterrows():
        if term in row["clean_question"].split(" "):
            if row["high_value"] == 1:
                high_count += 1
            else:
                low_count += 1
    return high_count, low_count

comparison_terms = list(terms_used)[:5]
observed_expected = []
for term in comparison_terms:
    observed_expected.append(count_usage(term))

Hello, Amol.

I would expect you to get different results even using the same solution on multiple runs. There’s part of the solution that rests on random behavior, specifically when you create comparison_terms.

Sets are unordered, so when you create list using a set and extract a sample (as is the case here), you may end up with a different lists on each different run.

Thanks, Bruno! It makes sense now.