Allie H
Allie H

Reputation: 121

python comparing elements in dictionary to a float

If I have a dictionary of pvalues, such that accessing pvalues[i][classes[j]] gives the pvalue from comparing class j to other classes in row i. However, when I try to iterate over the dictionary to find the significant values (i.e., if pvalues[i][classes[j]] < 0.05), I get TypeError: unorderable types: list() < float(). Is there anyway to compare the list elements to the 0.05 float without flattening the list and losing the class designations? Thanks.

Upvotes: 0

Views: 153

Answers (1)

Shasha99
Shasha99

Reputation: 1916

As you mentioned in your comment, Your pvalues[i][classes[j]] is actually giving a list which is then being compare to float. You should compare the first element of that list and the float instead :

if pvalues[i][classes[j]][0] < .5 :
    print("it worked!!!")

Upvotes: 2

Related Questions